
//
//  SpaceEditController.m
//  cutter
//
//  Created by ZhangLi on 16/1/11.
//  Copyright © 2016年 e360. All rights reserved.
//

#import "SpaceEditController.h"
#import "SpacePanoController.h"
#import "SpacePhotoView.h"
#import "TMGlobal.h"
#import "TMLoader.h"
#import "TMRequest.h"
#import "TMJSON.h"
#import "TMUtils.h"
#import "SpaceCustom.h"
#import <CommonCrypto/CommonDigest.h>
#import <AVFoundation/AVFoundation.h>
#import "ProductDetailCtrl.h"
#import "UserCenterPick.h"
#import "TMCoverFlowSpace.h"
#import "OtherOrder.h"
#import <AVKit/AVKit.h>
//
#import "ProductCustom.h"

@implementation UICollectionViewColorCell
-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        self.imageview.layer.borderWidth=2;
        [self.imageview.layer setBorderColor:[[UIColor colorWithRed:71.00/255.00 green:148.00/255.00 blue:239.00/255.00 alpha:1] CGColor]];
    }else{
        self.imageview.layer.borderWidth=0;
        [self.imageview.layer setBorderColor:[[UIColor blackColor] CGColor]];
    }
}
@end
//
@implementation ButtonLable
@end

@implementation HouseDetailLayer

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self=[super initWithCoder:aDecoder];
    if (self) {
        [self setLableView:[[UIView alloc] initWithFrame:self.bounds]];
        [self setTipsView2:[[UIView alloc] initWithFrame:self.bounds]];
        [self setTipsView:[[UIView alloc] initWithFrame:self.bounds]];
    }
    return self;
}
-(NSMutableDictionary *)layers{
    if (nil == _layers) {
        [self setLayers:[NSMutableDictionary dictionary]];
    }
    return _layers;
}
-(void)setImage:(NSString*)file index:(NSUInteger)index{
    id key = [NSString stringWithFormat:@"%ld",(long)index];
    UIImageView *imageView = [self.layers objectForKey:key];
    if (nil == imageView) {
        imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self.layers setObject:imageView forKey:key];
        [self addSubview:imageView];
        //排序
        NSArray *layers = [self.layers.allKeys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            if ([obj1 integerValue] > [obj2 integerValue]) {
                return -1;
            }
            if ([obj1 integerValue] < [obj2 integerValue]) {
                return 1;
            }
            return 0;
        }];
        for (id key in layers) {
            UIImageView *img = [self.layers objectForKey:key];
            [self addSubview:img];
        }
        [self addSubview:self.tipsView];
        [self addSubview:self.tipsView2];
        [self addSubview:self.lableView];
    }
    [AppData loadImage:file view:imageView];
}
-(void)layoutSubviews{
    [super layoutSubviews];
    for (UIView *view in self.subviews) {
        [view setFrame:self.bounds];
    }
}
-(void)reset{
    [self.layers removeAllObjects];
    [self.lableView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.tipsView2.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.tipsView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
@end
//

@implementation SpacePropertyListViewSingleCell

-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    if (self.selected) {
        if([self.index intValue]==24){
            self.iconview.hidden = NO;
        }else{
            self.iconview.hidden = YES;
        }
        self.imageview.layer.borderWidth=2;
        [self.imageview.layer setBorderColor:[[UIColor colorWithRed:71.00/255.00 green:148.00/255.00 blue:239.00/255.00 alpha:1] CGColor]];
    }else{
        self.iconview.hidden = YES;
        self.imageview.layer.borderWidth=0;
        [self.imageview.layer setBorderColor:[[UIColor blackColor] CGColor]];
    }
}
-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    [self setNeedsDisplay];
}
@end

@implementation SpacePropertyContainer

-(void)viewDidLoad{
    [super viewDidLoad];
    
    self.tempSection =0;
    self.roomDic = [NSMutableDictionary dictionary];
    
    self.view.backgroundColor = [UIColor clearColor];
    self.button1.hidden = YES;
    self.button2.hidden = YES;
    self.button3.hidden = YES;
    self.button4.hidden = YES;
    [self initData];
    self.button1.hidden = NO;
    [self.closeView addTarget:self action:@selector(closeTouch:) forControlEvents:UIControlEventTouchUpInside];
    //
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self                                      action:@selector(handleSingleFingerEvent:)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    singleFingerOne.cancelsTouchesInView = NO;
    [self.collectionView addGestureRecognizer:singleFingerOne];
    //
}
- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender
{
    self.collectionView_color.hidden = YES;
    self.arrow.hidden = YES;
}
-(void)closeTouch:(UIButton *)sender
{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"closeTouch" object:nil];
}
-(void)initData{
    
    //
    TMCoverFlowSpace *lay = (TMCoverFlowSpace *)self.collectionView.collectionViewLayout;
    lay.expand = 90;
        if([self.index intValue]==1||[self.index intValue]==3){
            if([self.index intValue]==1)self.button1.hidden = NO;
            if([self.index intValue]==3)self.button3.hidden = NO;
            lay.degree = 90;
            [self.collectionView reloadData];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:0 inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
        }else{
            if([self.index intValue]==2){
                self.button2.hidden = NO;
                lay.degree = 30;
                if(self.DicIndexPath2){
                    [self.collectionView reloadData];
                    NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2];
                    NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.section inSection:0];
                    [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
                    [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
                }
            }
            
            
            //
            if([self.index intValue]==4){
                self.button4.hidden = NO;
                lay.degree = 30;
                if(self.DicIndexPath){
                    [self.collectionView reloadData];
//
                    
                     NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath];
//                    NSIndexPath *p = (NSIndexPath *)[self.DicIndexPath objectForKey:[NSNumber numberWithInteger:self.pointID_yz]];
                    NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.section inSection:0];
                    [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
                    [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
                }
            }
            //
        }
        
    
}
-(void)updata{
    for(id item in self.collectionView.subviews){
        [item removeFromSuperview];
    }
    count=0;
    self.button1.hidden = YES;
    self.button2.hidden = YES;
    self.button3.hidden = YES;
    self.button4.hidden = YES;
    if([self.roomDic objectForKey:@"1"]&&[self.index intValue]==1){
        self.button1.hidden = NO;
        [self.collectionView reloadData];
        NSIndexPath *indexPath=(NSIndexPath *)[self.roomDic objectForKey:@"1"];
        [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
        [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
    }
    else if([self.roomDic objectForKey:@"3"]&&[self.index intValue]==3){
        self.button3.hidden = NO;
        [self.collectionView reloadData];
        NSIndexPath *indexPath=(NSIndexPath *)[self.roomDic objectForKey:@"3"];
        [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
        [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
    }
    else if([self.index intValue]==4&&[[self.roomDic objectForKey:@"4"] count]>0)
    {
        self.arrow.hidden = YES;
        self.collectionView_color.hidden = YES;
        self.button4.hidden = NO;
        self.DicIndexPath =[self.roomDic objectForKey:@"4"];
        if([self.pointDic count]>0){
            [self.collectionView reloadData];
            self.isplay=1;
            
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath];
//            NSIndexPath *p = (NSIndexPath *)[self.DicIndexPath objectForKey:[NSNumber numberWithInteger:self.pointID_yz]];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.section inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
            return;
        }
        if([self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath]){
            [self.collectionView reloadData];
            self.isplay=1;
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.section inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
            return;
        }else
        {
            [self.collectionView reloadData];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:0 inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
            return;
        }
    }
    else if([self.index intValue]==2&&[[self.roomDic objectForKey:@"2"] count]>0){
        self.arrow.hidden = YES;
        self.collectionView_color.hidden = YES;
        self.button2.hidden = NO;
        self.DicIndexPath2 =[self.roomDic objectForKey:@"2"];
        if([self.pointDic count]>0){
            [self.collectionView reloadData];
            self.isplay=1;
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.section inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
            return;
        }
        
        for (id key in self.DicIndexPath2.allKeys)
        {
            NSLog(@"%@",[key class]);
        }
        
        //
        
        if([self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2]){
            [self.collectionView reloadData];
            self.isplay=1;
            
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.section inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
            return;
        }else
        {
            [self.collectionView reloadData];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:0 inSection:0];
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
            return;
        }
        
    }else{
        [self initData];
    }
}
-(id)feachForKey:(id)key object:(NSDictionary*)object{
    for (id k in object.allKeys) {
        if ([k intValue] == [key intValue]) {
            return [object objectForKey:k];
        }
    }
    return nil;
}
-(void)updata_color{
    for(id item in self.collectionView_color.subviews){
        [item removeFromSuperview];
    }
    self.isplay=0;
    if([self.index intValue]==4&&[[self.roomDic objectForKey:@"4"] count]>0)
    {
        if([self.pointDic count]>0){
            
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.row inSection:0];
            [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView_color didSelectItemAtIndexPath:p];
            return;
        }
        if([self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath]){
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.row inSection:0];
            [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView_color didSelectItemAtIndexPath:p];
            return;
        }else
        {
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:0 inSection:0];
            [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView_color didSelectItemAtIndexPath:indexPath];
            return;
            
        }
    }
    else if([self.index intValue]==2&&[[self.roomDic objectForKey:@"2"] count]>0){
        if([self.pointDic count]>0){
            
            
            NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.row inSection:0];
            [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView_color didSelectItemAtIndexPath:p];
            return;
        }
        if([self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2]){
            NSIndexPath *p = (NSIndexPath *)[self.DicIndexPath2 objectForKey:[NSNumber numberWithInteger:self.pointID]];
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.row inSection:0];
            [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView_color didSelectItemAtIndexPath:p];
            return;
        }else
        {
            NSIndexPath *indexPath=[NSIndexPath indexPathForItem:0 inSection:0];
            [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self collectionView:self.collectionView_color didSelectItemAtIndexPath:indexPath];
            return;
        }
        
    }else{
        if([self.index intValue]==2){
            if(self.DicIndexPath2){
                NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID] object:self.DicIndexPath2];
                NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.row inSection:0];
                [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
                [self collectionView:self.collectionView_color didSelectItemAtIndexPath:indexPath];
            }
        }
        
        
        //
        if([self.index intValue]==4){
            if(self.DicIndexPath){
                
                NSIndexPath *p = (NSIndexPath *)[self feachForKey:[NSNumber numberWithInteger:self.pointID_yz] object:self.DicIndexPath];
                NSIndexPath *indexPath=[NSIndexPath indexPathForItem:p.row inSection:0];
                [self.collectionView_color selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
                [self collectionView:self.collectionView_color didSelectItemAtIndexPath:indexPath];
            }
        }
        //
    }
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if(collectionView == self.collectionView_color){
        return 1;
    }
    if(self.data){
        if([self.index intValue]==1){
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            self.newarray = [[NSMutableArray alloc]init];
            for (NSDictionary * obj in self.data) {
                if([[obj objectForKey:@"house_sample_room_match_class"] count]>0){
                    
                    NSString *name = [[obj objectForKey:@"house_sample_room_match_class"] objectForKey:@"classname"];
                    NSString *hardpacked = [[obj objectForKey:@"house_sample_room_match_class"] objectForKey:@"hardpacked"];
                    if( [hardpacked intValue]==0){
                        if (dic[name] == nil) {
                            NSMutableArray *arr = [NSMutableArray array];
                            [arr addObject:obj];
                            dic[name] = arr;
                        }
                        else
                        {
                            NSMutableArray *arr = dic[name];
                            [arr addObject:obj];
                        }
                    }
                    
                }
                
                
            }
            for (id key in dic) {
                [self.newarray addObject:dic[key]];
            }
            
            NSArray *sort=[self.newarray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
                if ([obj1[0][@"sort"] floatValue] > [obj2[0][@"sort"] floatValue]) {
                    return NSOrderedDescending;
                }
                if ([obj1[0][@"sort"] floatValue] < [obj2[0][@"sort"] floatValue]) {
                    return NSOrderedAscending;
                }
                return NSOrderedSame;
            }];
            [self.newarray removeAllObjects];
            self.newarray = sort.mutableCopy;

            
            return [self.newarray count];
        }
        if([self.index intValue]==3){
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            self.newarray = [[NSMutableArray alloc]init];
            for (NSDictionary * obj in self.data) {
                if([[obj objectForKey:@"house_sample_room_match_class"] count]>0){
                    NSString *name = [[obj objectForKey:@"house_sample_room_match_class"] objectForKey:@"classname"];
                    NSString *hardpacked = [[obj objectForKey:@"house_sample_room_match_class"] objectForKey:@"hardpacked"];
                    if([hardpacked intValue]==1){
                        if (dic[name] == nil) {
                            NSMutableArray *arr = [NSMutableArray array];
                            [arr addObject:obj];
                            dic[name] = arr;
                        }
                        else
                        {
                            NSMutableArray *arr = dic[name];
                            [arr addObject:obj];
                        }
                    }
                }
                
            }
            for (id key in dic) {
                [self.newarray addObject:dic[key]];
            }
            
            
            NSArray *sort=[self.newarray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
                if ([obj1[0][@"sort"] floatValue] > [obj2[0][@"sort"] floatValue]) {
                    return NSOrderedDescending;
                }
                if ([obj1[0][@"sort"] floatValue] < [obj2[0][@"sort"] floatValue]) {
                    return NSOrderedAscending;
                }
                return NSOrderedSame;
            }];
            [self.newarray removeAllObjects];
            self.newarray = sort.mutableCopy;
            
            return [self.newarray count];
        }
        if([self.index intValue]==2||[self.index intValue]==4){
            return 1;
        }
    }
    return 0;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if(collectionView == self.collectionView_color){
        if([self.colorarray count]>0){
            return  [[self.colorarray objectAtIndex:section] count];
        }
        return 1;
    }
    if([self.index intValue]==2){
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        self.newarray = [[NSMutableArray alloc]init];
        self.sort =[self.data objectForKey:@"sort"];
        id temp =[self.data objectForKey:@"class_product"];
        for (NSDictionary * obj in temp) {
            if([[obj objectForKey:@"product"] count]>0){
                NSString *parentid = [[obj objectForKey:@"product"] objectForKey:@"parentid"];
                NSString *hardpacked = [[obj objectForKey:@"product"] objectForKey:@"temp_hardpacked"];
                if(parentid){
                    if([hardpacked intValue]==0){
                        if (dic[parentid] == nil) {
                            NSMutableArray *arr = [NSMutableArray array];
                            [arr addObject:obj];
                            dic[parentid] = arr;
                        }
                        else
                        {
                            NSMutableArray *arr = dic[parentid];
                            [arr addObject:obj];
                        }
                    }
                }
                
            }
            
        }
        for (id key in dic) {
            [self.newarray addObject:dic[key]];
        }
        
        
        return [self.newarray count];

        
    }
    if([self.index intValue]==4){
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        self.newarray = [[NSMutableArray alloc]init];
        self.sort =[self.data objectForKey:@"sort"];
        id temp =[self.data objectForKey:@"class_product"];
        for (NSDictionary * obj in temp) {
            if([[obj objectForKey:@"product"] count]>0){
                NSString *parentid = [[obj objectForKey:@"product"] objectForKey:@"parentid"];
                NSString *hardpacked = [[obj objectForKey:@"product"] objectForKey:@"temp_hardpacked"];
                //if(parentid){
                    if([hardpacked intValue]==1){
                        if (dic[parentid] == nil) {
                            NSMutableArray *arr = [NSMutableArray array];
                            [arr addObject:obj];
                            dic[parentid] = arr;
                        }
                        else
                        {
                            NSMutableArray *arr = dic[parentid];
                            [arr addObject:obj];
                        }
                    }
               // }
                
            }
            
        }
        for (id key in dic) {
            [self.newarray addObject:dic[key]];
        }
        
        return [self.newarray count];
    }
    //
    if([self.index intValue]== 1||[self.index intValue]== 3){
        if([self.newarray count]>0){
            
            
            return [[self.newarray objectAtIndex:section] count];
        }
    }
    return [self.data count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if(collectionView == self.collectionView_color){
        UICollectionViewColorCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
        cell.backgroundColor=[UIColor clearColor];
        if([self.colorarray count]>0)
        {
            NSString *file =[[[self.colorarray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"thumb"];
            [AppData loadImage:file view:cell.imageview];
        }
        
        return cell;
    }
    //
    SpacePropertyListViewSingleCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    if([self.index intValue]== 1||[self.index intValue]== 3){
        cell.index=@"13";
        if([self.newarray count]>0){
            cell.nameView.text = [[[self.newarray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"];
            NSString *file =[[[self.newarray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"thumb"];
            [AppData loadImage:file view:cell.imageview];
        }
        
        UICollectionViewLayoutAttributes *att =[collectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:indexPath];
        if(indexPath.row == 0){
            UIButton *button = (UIButton *)[self.collectionView viewWithTag:indexPath.section+1000];
            UILabel *nameView = (UILabel *)[self.collectionView viewWithTag:indexPath.section+100];
            
            if(nameView==nil){
                button=[[UIButton alloc]initWithFrame:CGRectZero];
                button.backgroundColor = [UIColor colorWithHex:0x1e1e20];
                [button setCorner:5.0];
                //
                nameView=[[UILabel alloc]initWithFrame:CGRectZero];
                nameView.lineBreakMode =NSLineBreakByWordWrapping;
                nameView.numberOfLines =100;
                //
                
            }
            button.frame=CGRectMake(att.frame.origin.x-50, 15, 41, 100);
            nameView.frame=CGRectMake(att.frame.origin.x-45, 0, 30, 132);
            if([self.index intValue]==2||[self.index intValue]==4){
                nameView.text = [[[[self.newarray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"product"] objectForKey:@"productsn"];;
            }
            if([self.index intValue]==1||[self.index intValue]==3){
                if([self.newarray count]>0){
                    nameView.text = [[[[self.newarray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"house_sample_room_match_class"] objectForKey:@"classname"];
                }
            }
            [self.collectionView addSubview:button];
            [self.collectionView addSubview:nameView];
            nameView.textColor = [UIColor whiteColor];
            nameView.font = [UIFont systemFontOfSize:12.0];
            nameView.tag =indexPath.section+100;
            button.tag =indexPath.section+1000;
        }

        //name
    }
    //
    if([self.index intValue]== 2||[self.index intValue]== 4){
        cell.index=@"24";
        cell.nameView.text = [[[[self.newarray objectAtIndex:indexPath.row] firstObject] objectForKey:@"product"] objectForKey:@"productsn"];
        
        NSString *file =[[[self.newarray objectAtIndex:indexPath.row] firstObject] objectForKey:@"thumb"];
        [AppData loadImage:file view:cell.imageview];
    }
    return cell;
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if(collectionView==self.collectionView_color){
        NSIndexPath *indexpath =[NSIndexPath indexPathForItem:indexPath.row inSection:self.tempSection];
        //软装单品
        if(self.onSelected){
            if([self.colorarray count]>0){
                self.data=nil;
                self.data =[self.colorarray firstObject];
                
                self.onSelected(indexpath,self);
                return;
                
            }
        }
        //硬装单品
        if(self.onSelected3){
            if([self.colorarray count]>0){
                self.data=nil;
                self.data =[self.colorarray firstObject];
                self.onSelected3(indexpath,self);
                return;
            }
        }
        return;
    }
    self.colorarray = [[NSMutableArray alloc]init];
    if(collectionView == self.collectionView && ([self.index intValue]==2||[self.index intValue]==4)){
        count++;
        if([self.newarray count]>0){
            if(indexPath.row!=[[NSNumber numberWithInteger:self.tempSection] integerValue]){
                self.arrow.hidden = NO;
                self.collectionView_color.hidden = NO;
            }else{
                self.isplay = 1;
                self.collectionView_color.hidden=!self.collectionView_color.hidden;
                self.arrow.hidden = !self.arrow.hidden;
            }
            
            if(count==1){
                self.arrow.hidden = YES;
                self.collectionView_color.hidden = YES;
            }
            NSLog(@"self.index    ===  %ld",(long)count);
//            if()
            dispatch_async(dispatch_get_main_queue(), ^{
                 self.arrow.frame = CGRectMake(indexPath.row*110+(110/2)+88+indexPath.row*10, self.arrow.frame.origin.y, self.arrow.frame.size.width, self.arrow.frame.size.height);
            });
            self.tempSection = indexPath.row;
//            NSLog(@"===    %ld",[[self.newarray objectAtIndex:indexPath.row] count]);
            if([self.index intValue]==2&&self.isplay==0){
                NSIndexPath *indexpath =[NSIndexPath indexPathForItem:0 inSection:self.tempSection];
                if(indexpath){
                    [self.DicIndexPath2 setObject:indexpath forKey:[NSNumber numberWithInteger:self.pointID]];
                }
                if(self.onSelected_rz){
                    if(self.DicIndexPath2){
                        self.onSelected_rz(self,self.DicIndexPath2);
                        
                    }
                }
            }
            if([self.index intValue]==4&&self.isplay==0){
                NSIndexPath *indexpath =[NSIndexPath indexPathForItem:0 inSection:self.tempSection];
                if(indexpath){
                    [self.DicIndexPath setObject:indexpath forKey:[NSNumber numberWithInteger:self.pointID_yz]];
                }
                if(self.onSelected_yz){
                    if(self.DicIndexPath){
                        self.onSelected_yz(self,self.DicIndexPath);
                        
                    }
                }
            }
            if([self.newarray count]>indexPath.row)
            {
                [self.colorarray addObject:[self.newarray objectAtIndex:indexPath.row]];
                [self.collectionView_color reloadData];
                [self updata_color];
            }
            //
            
        }
    }
    
    
   
    //硬装套餐
    if(self.onSelected2){
        if([self.newarray count]>0){
            self.isplay = 1;
            self.data=nil;
            self.data =[self.newarray objectAtIndex:indexPath.section];
            self.onSelected2(indexPath,self);
            return;
        }
    }
    //软装套餐
    if(self.onSelected1){
        if([self.newarray count]>0){
            self.isplay = 1;
            self.data=nil;
            self.data =[self.newarray objectAtIndex:indexPath.section];
            self.onSelected1(indexPath,self);
            return;
        }
    }
    
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if(self.collectionView_color==collectionView){
        CGFloat tw = [self.colorarray count] * 66 - 10;
        if (tw < collectionView.bounds.size.width) {
            CGFloat s = (collectionView.bounds.size.width - tw ) / 2 - 66;
            return UIEdgeInsetsMake(0, s, 0, s);
        }
        return UIEdgeInsetsZero;
    }
    return UIEdgeInsetsZero;
}

@end
//
@implementation SpaceProductListHead

-(IBAction)clickSelectedButton:(UIButton*)sender
{
    id item = nil;
    
    if(!self.isHard){
        
        for(int i=0;i<[[[self.data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[[self.data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
            if([[item objectForKey:@"sub"] count]>0){
                for(int a=0;a<[[item objectForKey:@"sub"] count];a++){

                    item[@"sub"][a][@"selected"] = [NSNumber numberWithBool:!sender.selected];
                    
                }
            }else{
             
                item[@"selected"]= [NSNumber numberWithBool:!sender.selected];
            }
            
        }
        
            }else{
        
        
       
        for(int i=0;i<[[[self.data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[self.data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
         
            
            item[@"product"][@"selected"] = [NSNumber numberWithBool:!sender.selected];
        }
        
    }
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"RefreshProductList" object:nil];

}

-(void)setData:(NSMutableDictionary *)data
{
    if(_data != data)
    {
        _data = nil;
        
        _data = data;
        
        if (data) {
            [self refreshUI];
        }
    }
}

-(void)refreshUI{
    float total = 0;
    BOOL allProductSelected = YES;
    id item = nil;
    //
    if(!self.isHard){
        for(int i=0;i<[[[self.data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
            item =[[[[[[self.data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
            if([[item objectForKey:@"sub"] count]>0){
                for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
                    total+=[[[[item objectForKey:@"sub"] objectAtIndex:a] objectForKey:@"price"] integerValue];
                    if ([item[@"sub"][a][@"selected"]boolValue] == NO) {
                        allProductSelected = NO;
                    }
                }
            }else{
                total+=[[item objectForKey:@"price"] integerValue];
                
                if ([item[@"selected"]boolValue] == NO) {
                    allProductSelected = NO;
                }
            }
        }
        [self.tilteView setText:@"软装"];
    }else{
        if([self.data objectForKey:@"yz"]){
            [self.tilteView setText:@"硬装"];
            for(int i=0;i<[[[self.data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
                
                item =[[[[[self.data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
                total+=[[[item objectForKey:@"product"] objectForKey:@"price"] integerValue];
                
                if ([item[@"product"][@"selected"]boolValue] == NO) {
                    allProductSelected = NO;
                }
            }
        }
    }
    self.priceView.text =[NSString stringWithFormat:@"套餐价：￥%.2f",total];
    self.selectView.selected  = allProductSelected;

}


@end
//
@implementation SpaceProductListCellCell2
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}


-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        
    }
    
    return self;
}


-(IBAction)clickSelectedBtn:(UIButton *)sender
{
    
    
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
}


-(void)configCellWithCellInfo:(NSMutableDictionary *)cellInfo
{
    self.cellInfo = cellInfo;
    
    if (self.cellInfo) {
        
        
        [self refreshUI];
    }
}

-(void)refreshUI
{
    self.labelView.text = [NSString stringWithFormat:@"%@",[self.cellInfo objectForKey:@"content"]];
    self.nameView.text = [NSString stringWithFormat:@"%@",[self.cellInfo objectForKey:@"productname"]];
    self.priceView.text =[NSString stringWithFormat:@"￥%@",[self.cellInfo objectForKey:@"price"]];
    self.countView.text =[NSString stringWithFormat:@"x%@",[self.cellInfo objectForKey:@"productcount"]];
    self.selectView.selected = [self.cellInfo[@"selected"]boolValue];
    
}

-(IBAction)cellTouch:(UIButton *)btn
{
    btn.selected = !btn.selected;
    
    self.cellInfo[@"selected"] = [NSNumber numberWithBool:btn.selected];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"RefreshProductList" object:nil];
}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
    
}
@end

@implementation SpaceProductListCellCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
       }
    return self;
}


-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        
    }
    
    return self;
}


-(IBAction)clickSelectedBtn:(UIButton *)sender
{
    
    
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
}


-(void)configCellWithCellInfo:(NSMutableDictionary *)cellInfo
{
    self.cellInfo = cellInfo;
    
    if (self.cellInfo) {
        
        
        [self refreshUI];
    }
}

-(void)refreshUI
{
    
    self.nameView.text = [NSString stringWithFormat:@"%@",[self.cellInfo objectForKey:@"productname"]];
    self.specView.text = [NSString stringWithFormat:@"%@",[self.cellInfo objectForKey:@"size"]];
    self.clolorView.text = @"";
    self.priceView.text =[NSString stringWithFormat:@"￥%@",[self.cellInfo objectForKey:@"price"]];
    self.countView.text =[NSString stringWithFormat:@"x%@",[self.cellInfo objectForKey:@"productcount"]];
    [AppData loadImage:[self.cellInfo objectForKey:@"thumb400_jpg"] view:self.imageView];
    self.selectView.selected = [self.cellInfo[@"selected"]boolValue];

}

-(IBAction)cellTouch:(UIButton *)btn
{
    btn.selected = !btn.selected;
    
    self.cellInfo[@"selected"] = [NSNumber numberWithBool:btn.selected];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"RefreshProductList" object:nil];
}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];

}
@end
//

@implementation SpaceProductListBigCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.listView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [self.listView setBackgroundColor:[UIColor clearColor]];
        self.listView.scrollEnabled = NO;
        self.listView.autoresizingMask = UIViewAutoresizingFlexibleHeight;    }
    return self;
}
//UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if([self.data objectForKey:@"rz"]&&[self.data objectForKey:@"yz"]){
         return 2;
    }
    if([self.data objectForKey:@"rz"]||[self.data objectForKey:@"yz"]){
        return 1;
    }
   return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    SpaceProductListHead *headView=(id)[tableView dequeueReusableCellWithIdentifier:@"headIdentifier2"];
//    [headView.selectView addTarget:self action:@selector(headTouch:) forControlEvents:UIControlEventTouchUpInside];

    if(section==0){
        
        headView.isHard = NO;
     
        
    
    }else{
        
        headView.isHard = YES;
       
    }
    
    headView.data = self.data;
    
    
    //@"套餐价：￥399900.00";
    return headView;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section==0){
        
        self.dat = [[NSMutableArray alloc]init];
        id rz = [[self.data objectForKey:@"rz"] objectForKey:@"data"];
        for(int i=0;i<[rz count];i++){
            id item =[[[[[rz objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"] objectForKey:@"sub"];
            if([item count]>0){
                for(int a=0;a<[item count];a++){
                    [self.dat addObject:[item objectAtIndex:a]];
                }
            }else{
                if([[[[rz objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"]){
                    [self.dat addObject:[[[[rz objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"]];
                }
                
            }
            
        }

        //
        return [self.dat count];
    }
    if(section==1){
        return [[[self.data objectForKey:@"yz"] objectForKey:@"data"]count];
    }
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    id temp = nil;
    if(indexPath.section==0){
        temp = [self.dat objectAtIndex:indexPath.row];
    }else{
        temp =[[[[[[self.data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:indexPath.row] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
        if(isEmpty([temp objectForKey:@"thumb400_jpg"]))
        {
            SpaceProductListCellCell2 *cell2=[tableView dequeueReusableCellWithIdentifier:@"otherIdentifier"];
            [cell2 configCellWithCellInfo:temp];
            return cell2;
        }
    }
    
    
    SpaceProductListCellCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellIdentiflter3"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell configCellWithCellInfo:temp];
    //
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
-(void)layoutSubviews{
    [super layoutSubviews];
    
}
//
-(void)cellTouch:(UIButton *)sender{
    sender.selected = !sender.selected;
}
-(void)headTouch:(UIButton *)sender{
    sender.selected = !sender.selected;
    [[NSNotificationCenter defaultCenter]postNotificationName:@"headTouch2" object:nil];
}
@end
//
@implementation SpaceProductListBigHead
{

}

-(void)setData:(NSMutableDictionary *)data
{
    if (_data != data) {
        
        _data  = nil;
        
        _data = data;
        
        if (_data) {
            
            [self refreshUI];
            
        }
    }
}

-(void)refreshUI
{
    
    id item = nil;
    
    
    BOOL allPrductSelected = YES;
    
            for(int i=0;i<[[[self.data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
    
                item =[[[[[[self.data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
                if([[item objectForKey:@"sub"] count]>0){
                    for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
    
                        if([item[@"sub"][a][@"selected"]boolValue] == NO)
                        {
                            allPrductSelected = NO;
                        }
                    }
                }else{
    
                    if ([item[@"selected"] boolValue] == NO) {
                        allPrductSelected = NO;
                    }
                }
    
            }
    
     
    
            for(int i=0;i<[[[self.data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
    
                item =[[[[[self.data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
    
    
                if ([item[@"product"][@"selected"] boolValue] == NO) {
                    
                    allPrductSelected = NO;
                    
                }
            }
    
    
    self.selectView.selected = allPrductSelected;
        
}

-(IBAction)clickSelectedButton:(UIButton *)sender
{
    
    id item = nil;

    for(int i=0;i<[[[self.data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
        
        item =[[[[[[self.data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
        if([[item objectForKey:@"sub"] count]>0){
            for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
                
                item[@"sub"][a][@"selected"]=[NSNumber numberWithBool:!sender.selected];
            }
        }else{
            item[@"selected"]=[NSNumber numberWithBool:!sender.selected];
            
        }
        
    }
    
    
    
    for(int i=0;i<[[[self.data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
        
        item =[[[[[self.data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
        
        item[@"product"][@"selected"]=[NSNumber numberWithBool:!sender.selected];
        
    }
    [[NSNotificationCenter defaultCenter]postNotificationName:@"RefreshProductList" object:nil];
    
}
@end
//
@implementation SpaceProductListLeftCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.backgroundColor = [UIColor clearColor];
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
    if (selected) {
        UIColor *color = [UIColor colorWithRed:71.0/255.0 green:148.0/255.0 blue:239.0/255.0 alpha:1];
        self.iconView.blend = color;
        self.lableView.textColor = [UIColor colorWithRed:71.0/255.0 green:148.0/255.0 blue:239.0/255.0 alpha:1];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }else{
        self.iconView.blend = nil;
        self.lableView.textColor = [UIColor colorWithRed:74.0/255.0 green:74.0/255.0 blue:74.0/255.0 alpha:1];
        self.contentView.backgroundColor = [UIColor clearColor];
        self.iconView.tintColor = [UIColor colorWithRed:74.0/255.0 green:74.0/255.0 blue:74.0/255.0 alpha:1];
    }
}
@end
//
@implementation SpaceProductList

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}


-(void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshProductList) name:@"RefreshProductList" object:nil];
    [self.leftView setBackgroundColor:[UIColor clearColor]];
    [self.leftView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    //
    [self.mainView setBackgroundColor:[UIColor clearColor]];
    [self.mainView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    [self.leftView selectRowAtIndexPath:[NSIndexPath indexPathForItem:[self.ID integerValue] inSection:0]animated:YES scrollPosition:UITableViewScrollPositionTop];
    [self.mainView selectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:[self.ID integerValue]]animated:YES scrollPosition:UITableViewScrollPositionTop];
    //count
    self.button1.enabled = NO;
    self.button2.enabled = NO;
    self.allprice.text=[NSString stringWithFormat:@"￥0.00"];
    self.allprice2.text=[NSString stringWithFormat:@"￥0.00"];
    self.allcount.text=[NSString stringWithFormat:@"0"];
    //
    
    if(self.type==0){
        [self updataState];
    }
    [self getnewArray];
//    [self.allbtton sendActionsForControlEvents:UIControlEventTouchUpInside];
}





-(void)refreshProductList
{
    [self updata];
    [self refreshUI];
    [self.mainView reloadData];
}


+(id)updataProduct:(id)data client:(id)client{
    NSMutableArray *temps = [NSMutableArray array];
    if ([data isKindOfClass:NSArray.class]) {
        for (id item in data) {
            if ([item isKindOfClass:NSDictionary.class]) {
                [temps addObject:item];
            }
        }
    }
    if ([data isKindOfClass:NSDictionary.class]) {
        [temps addObject:data];
    }
    //
    NSMutableArray *products = [NSMutableArray array];
    for (id temp in temps) {
        id uuid = [NSString uuid];
        id number = [temp objectForKey:@"number"];
        if(number == nil){
            number = [temp objectForKey:@"productcount"];
        }
        if(number == nil){
            number = [temp objectForKey:@"count"];
        }
        if(number == nil) {
            number = [NSNumber numberWithInt:1];
        }
        //
        NSMutableDictionary *iii = [NSMutableDictionary dictionary];
        [iii setValue:[client objectForKey:@"uuid"] forKey:@"clientuuid"];
        [iii setValue:[temp objectForKey:@"temp_hardpacked"] forKey:@"hardpacked"];
        [iii setValue:[temp objectForKey:@"matchid"] forKey:@"matchid"];
        [iii setValue:[temp objectForKey:@"suitid"] forKey:@"suitid"];
        [iii setValue:[temp objectForKey:@"id"] forKey:@"productid"];
        [iii setValue:number forKey:@"number"];
        [iii setValue:uuid forKey:@"uuid"];
        [iii setValue:temp forKey:@"product_detail"];
        [iii setValue:[temp objectForKey:@"suit"] forKey:@"suit"];
        [products addObject:iii];
    }
    return products;
}
//
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender{
    //
    if ([segue.destinationViewController isKindOfClass:OtherOrder.class]) {
        NSMutableArray *selectArray=[[NSMutableArray alloc]init];
        NSDictionary *client = [TMGlobal valueForKey:@"client"];
        if(client){
            for(int i=0;i<[self.array count];i++){
                if([[[self.array objectAtIndex:i] objectForKey:@"selected"] integerValue]==1){
                    [selectArray addObject:[self.array objectAtIndex:i]];
                }
            }
            id arr = [SpaceProductList updataProduct:selectArray client:client];
            //
            OtherOrder *temp = segue.destinationViewController;
            [temp setClient:client];
            [temp setSource:arr];
            
        }else{
            [UIAlertController show:@"请先选择用户！" message:nil buttons:nil handler:nil];
        }
        
    }
    //
    if ([segue.destinationViewController isKindOfClass:UINavigationController.class]) {
        UINavigationController *ctrl = segue.destinationViewController;
        if ([[ctrl.viewControllers firstObject] isKindOfClass:UserCenterSelect.class]) {
            UserCenterSelect *root = [ctrl.viewControllers firstObject];
            [root setOnSelected:^(id target, id result){
                [self dismissViewControllerAnimated:YES completion:nil];
                if(result!=nil){
                    [TMGlobal setValue:result forKey:@"client"];
                    if ([segue.identifier isEqualToString:@"cartSegue"]) {
                        [self addCart:sender];
                    }
                }
            }];
        }
    }
}
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender{
    if ([TMGlobal valueForKey:@"client"]) {
        if ([identifier isEqualToString:@"cartSegue"]) {
            [self addCart:sender];
            return NO;
        }
        
    }
    return YES;
}

//

//
- (IBAction)addCart:(id)sender
{
    NSLog(@"%@",self.array);
    NSMutableArray *selectArray=[[NSMutableArray alloc]init];
    for(int i=0;i<[self.array count];i++){
        if([[[self.array objectAtIndex:i] objectForKey:@"selected"] integerValue]==1){
            [selectArray addObject:[self.array objectAtIndex:i]];
        }
    }
    
    NSDictionary *client = [TMGlobal valueForKey:@"client"];
    if ([AppData userAddCart:selectArray client:client]) {
        [TMAlert showAtView:self.view image:@"img_Prompt_ShoppingCar_OK.png"];
    }
    
//    if ([AppData userAddCart:selectArray client:nil]) {
//        [TMAlert showAtView:self.view image:@"img_Prompt_ShoppingCar_OK.png"];
//    }
}

-(void)getnewArray{

    self.array = [[NSMutableArray alloc]init];
    if([self.data_right count]>0){
        for(int i=0;i<[self.data_right count];i++){
            id tp= [[[self.data_right objectAtIndex:i] objectForKey:@"rz"] objectForKey:@"data"];
            for(int j=0;j<[tp count];j++){
                id it = [[self.data_right objectAtIndex:i] objectForKey:@"rz"];
                id item =[[[[[tp objectAtIndex:j] objectForKey:@"class_product"] firstObject] objectForKey:@"product"] objectForKey:@"sub"];
                if([item count]>0){
                    for(int a=0;a<[item count];a++){
                        [[item objectAtIndex:a] setValue:[it objectForKey:@"suitid"] forKey:@"suitid"];
                        [[item objectAtIndex:a] setValue:[it objectForKey:@"hardpacked"] forKey:@"hardpacked"];
                        if (i < [self.data_left count]) {
                            [[item objectAtIndex:a] setValue:[self.data_left objectAtIndex:i] forKey:@"suit"];
                        }
                        [self.array addObject:[item objectAtIndex:a]];
                    }
                }else{
                    id itm = [[[[tp objectAtIndex:j] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
                    [itm setValue:[it objectForKey:@"suitid"] forKey:@"suitid"];
                    [itm setValue:[it objectForKey:@"hardpacked"] forKey:@"hardpacked"];
                    if (i < [self.data_left count]) {
                        [itm setValue:[self.data_left objectAtIndex:i] forKey:@"suit"];
                    }
                    if(itm){
                        [self.array addObject:itm];
                    }
                    
                }
                
            }
            //
            id tps= [[[self.data_right objectAtIndex:i] objectForKey:@"yz"] objectForKey:@"data"];
            if(tps){
                for(int k=0;k<[tps count];k++)
                {
                    id it = [[self.data_right objectAtIndex:i] objectForKey:@"yz"];
                    id item =[[[[tps objectAtIndex:k] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
                    if(item){
                        [item setValue:[it objectForKey:@"suitid"] forKey:@"suitid"];
                        [item setValue:[it objectForKey:@"hardpacked"] forKey:@"hardpacked"];
                        if (i < [self.data_left count]) {
                            [item setValue:[self.data_left objectAtIndex:i] forKey:@"suit"];
                        }
                        [self.array addObject:item];
                        
                    }
                }

            }
            //
        }
    }
    //
    int f=0;
    for(int a=0;a<[self.array count];a++)
    {
        if([[[self.array objectAtIndex:a] objectForKey:@"selected"] intValue]==0)
        {
            self.allbtton.selected = NO;
        }
        if([[[self.array objectAtIndex:a] objectForKey:@"selected"] intValue]==1)
        {
            f++;
            if(f==[self.array count])
            {
                self.allbtton.selected = YES;
                [self updataState];
            }else{
                [self updata];
            }
        }
    }
//    NSLog(@"%@",self.array);
}

-(void)updataState{

    id item = nil;
    
    for(int j=0;j<[self.data_right count];j++){
        
        id data = [self.data_right objectAtIndex:j];
        for(int i=0;i<[[[data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[[data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
            if([[item objectForKey:@"sub"] count]>0){
                for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
                    
                    item[@"sub"][a][@"selected"]=[NSNumber numberWithBool:1];
                }
            }else{
                item[@"selected"]=[NSNumber numberWithBool:1];
                
            }
            
        }
        
        
        
        for(int i=0;i<[[[data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
            
            item[@"product"][@"selected"]=[NSNumber numberWithBool:1];
            
        }
    }
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"allTouch" object:nil];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"RefreshProductList" object:nil];
}

- (IBAction)allTouch:(UIButton *)sender
{
    id item = nil;
    //
    for(int j=0;j<[self.data_right count];j++){
        
        id data = [self.data_right objectAtIndex:j];
        for(int i=0;i<[[[data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[[data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
            if([[item objectForKey:@"sub"] count]>0){
                for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
                    
                    item[@"sub"][a][@"selected"]=[NSNumber numberWithBool:!sender.selected];
                }
            }else{
                item[@"selected"]=[NSNumber numberWithBool:!sender.selected];
                
            }
            
        }
        
        for(int i=0;i<[[[data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
            
            item[@"product"][@"selected"]=[NSNumber numberWithBool:!sender.selected];
            
        }
    }
    
    
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"RefreshProductList" object:nil];
}


-(void)updata{
    CGFloat price = 0;
    NSInteger count = 0;
    //
    id item = nil;
    for(int j=0;j<[self.data_right count];j++){
        id data = [self.data_right objectAtIndex:j];
        for(int i=0;i<[[[data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[[data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
            if([[item objectForKey:@"sub"] count]>0){
                for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
                    if([item[@"sub"][a][@"selected"]boolValue])
                    {
                        price+=[item[@"sub"][a][@"price"] floatValue];
                        count+=[item[@"sub"][a][@"productcount"] intValue];
                    }
                }
            }else{
                if ([item[@"selected"] boolValue])
                {
                    price+=[item[@"price"] floatValue];
                    count+=[item[@"productcount"] intValue];
                }
            }
            
        }
        //
        for(int i=0;i<[[[data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
            if ([item[@"product"][@"selected"] boolValue])
            {
                price+=[item[@"product"][@"price"] floatValue];
                count+=[item[@"product"][@"productcount"] intValue];
            }
        }
    }
    
    [self.allcount setText:[NSString stringWithFormat:@"%ld", (long)count]];
    [self.allprice setText:[NSString stringWithFormat:@"￥%0.2f", price]];
    [self.allprice2 setText:[NSString stringWithFormat:@"￥%0.2f", price]];
    [self.button1 setEnabled:count > 0];
    [self.button2 setEnabled:count > 0];

}

-(void)refreshUI
{
    
    id item = nil;
    BOOL allPrductSelected = YES;
    for(int j=0;j<[self.data_right count];j++){
        id data = [self.data_right objectAtIndex:j];
        for(int i=0;i<[[[data objectForKey:@"rz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[[data objectForKey:@"rz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"];
            if([[item objectForKey:@"sub"] count]>0){
                for(int a=0;a<[[item objectForKey:@"sub"] count];a++){
                    
                    if([item[@"sub"][a][@"selected"]boolValue] == NO)
                    {
                        allPrductSelected = NO;
                    }
                }
            }else{
                
                if ([item[@"selected"] boolValue] == NO) {
                    allPrductSelected = NO;
                }
            }
            
        }
        
        
        
        for(int i=0;i<[[[data objectForKey:@"yz"] objectForKey:@"data"] count];i++){
            
            item =[[[[[data objectForKey:@"yz"] objectForKey:@"data"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
            
            
            if (item&&[item[@"product"][@"selected"] boolValue] == NO) {
                
                allPrductSelected = NO;
                
            }
        }
        
    
    }
    
    self.selectView.selected = allPrductSelected;
    
}

//

-(void)headTouch:(UIButton *)sender{
    NSLog(@"123");
    sender.selected=!sender.selected;
}
- (IBAction)closeTouch:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    self.onSelected_productList(self,sender);
}

//UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if(self.leftView==tableView){
        return 1;
    }
    return [self.data_right count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(self.leftView==tableView){
        return 0;
    }
    return 40;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(self.leftView==tableView){
        return [self.data_left count];
    }
    return 1;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(self.leftView==tableView){
        return nil;
    }
    SpaceProductListBigHead *headView=(id)[tableView dequeueReusableCellWithIdentifier:@"headIdentifier"];
    if (section < [self.data_left count]) {
        [headView.titleLable setText:[[self.data_left objectAtIndex:section] objectForKey:@"roomname"]];
    }
    if (section < [self.data_right count]) {
        headView.data = self.data_right[section];
    }
    return headView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    float dis=0;
    if(self.leftView==tableView){
        return 88;
    }
    NSMutableArray *dat = [[NSMutableArray alloc]init];
    id rz = [[[self.data_right objectAtIndex:indexPath.section] objectForKey:@"rz"] objectForKey:@"data"];
    id yz = [[[self.data_right objectAtIndex:indexPath.section] objectForKey:@"yz"] objectForKey:@"data"];
    for(int i=0;i<[rz count];i++){
         id item =[[[[[rz objectAtIndex:i] objectForKey:@"class_product"] firstObject] objectForKey:@"product"] objectForKey:@"sub"];
        if([item count]>0){
            for(int a=0;a<[item count];a++){
                [dat addObject:[item objectAtIndex:a]];
            }
        }else{
            id dat2 =[[[[rz objectAtIndex:i] objectForKey:@"class_product"] firstObject]objectForKey:@"product"];
            if(dat2)[dat addObject:dat2];
        }
        
    }
    for(int j=0;j<[yz count];j++){
        if([[[[yz objectAtIndex:j] objectForKey:@"class_product"] firstObject] objectForKey:@"product"] ){
            [dat addObject:[[[[yz objectAtIndex:j] objectForKey:@"class_product"] firstObject] objectForKey:@"product"]];
        }
        dis = 42;
    }
    NSLog(@"%ld",(unsigned long)[dat count]);
    return 44+[dat count]*120+dis;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(self.leftView==tableView){
        SpaceProductListLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentiflter"];
        if([self.data_right count]>indexPath.row){
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.lableView.text = [[self.data_right objectAtIndex:indexPath.row] objectForKey:@"suitname"];
            NSString *file=[[self.data_right objectAtIndex:indexPath.row] objectForKey:@"suiticon"];
            [AppData loadImage:file view:cell.iconView];
        }
        
        return cell;
    }
    SpaceProductListBigCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentiflter2"];
    if([self.data_right count]>indexPath.section){
        [cell setData:[self.data_right objectAtIndex:indexPath.section]];
    }
    [cell.listView reloadData];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(tableView == self.leftView){
        NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row];
        if ([self.mainView cellForRowAtIndexPath:scrollIndexPath] != nil) {
            [self.mainView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }
    }
    else
    {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSIndexPath *indexpath = self.mainView.indexPathsForVisibleRows.firstObject;
    NSIndexPath *path = [NSIndexPath indexPathForItem:indexpath.section inSection:0];
    if ([self.leftView cellForRowAtIndexPath:path]) {
        [self.leftView selectRowAtIndexPath:path animated:YES scrollPosition:UITableViewScrollPositionTop];
    }
}

@end


//标签
@implementation SpaceHotPointDetailCell
@end
//
@implementation SpaceHotPointDetail

-(void)viewDidLoad {
    [super viewDidLoad];
    
    
}

-(void)updata{
    NSDictionary *client = [TMGlobal valueForKey:@"client"];
    
    for(id dic in self.newarray){
        id fav = [AppData userHaveFavorite:dic client:client];
        if (fav) {
            self.addfav.selected = YES;
        }else{
            self.addfav.selected = NO;

        }
    }
}
//
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender{
    if ([segue.destinationViewController isKindOfClass:UINavigationController.class]) {
        UINavigationController *ctrl = segue.destinationViewController;
        if ([[ctrl.viewControllers firstObject] isKindOfClass:UserCenterSelect.class]) {
            UserCenterSelect *root = [ctrl.viewControllers firstObject];
            [root setOnSelected:^(id target, id result){
                [self dismissViewControllerAnimated:YES completion:nil];
                if(result!=nil){
                    [TMGlobal setValue:result forKey:@"client"];
                    if ([segue.identifier isEqualToString:@"favoriteSegue"]) {
                        [self favTouch:sender];
                    }
                    if ([segue.identifier isEqualToString:@"cartSegue"]) {
                        [self cartTouch:sender];
                    }
                }
            }];
        }
    }
}
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender{
    if ([TMGlobal valueForKey:@"client"]) {
        if ([identifier isEqualToString:@"favoriteSegue"]) {
            [self favTouch:sender];
        }
        if ([identifier isEqualToString:@"cartSegue"]) {
            [self cartTouch:sender];
        }
        return NO;
    }
    return YES;
}
-(void)favTouch:(UIButton *)sender {
    NSDictionary *client = [TMGlobal valueForKey:@"client"];

    //
    for(int i=0;i<[self.newarray count];i++){
        id dat = [self.newarray objectAtIndex:i];
        [dat setValue:@"product" forKey:@"t"];
        [AppData userEditFavorite:dat client:client];
    }
    [TMAlert showAtView:self.view image:@"img_Prompt_Favorites_OK.png"];
    //
    
    
    

}
-(void)cartTouch:(UIButton *)sender
{
    NSDictionary *client = [TMGlobal valueForKey:@"client"];
    if ([AppData userAddCart:self.newarray client:client]) {
        [TMAlert showAtView:self.view image:@"img_Prompt_ShoppingCar_OK.png"];
    }
    
}

//

- (IBAction)closeTouch:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

//UITableView
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
//
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    float count=0;
    float total=0;
    if([self.data count]==0){
        return 0;
    }
    self.newarray = [[NSMutableArray alloc]init];
    id item =[[self.data objectForKey:@"product"] objectForKey:@"sub"];
    if([item count]>0){
        for(int i=0;i<[item count];i++){
            count+=[[[item objectAtIndex:i] objectForKey:@"productcount"]floatValue];
            total+=[[[item objectAtIndex:i] objectForKey:@"price"]floatValue];
            [self.newarray addObject:[item objectAtIndex:i]];
        }
        self.totalCount.text =[NSString stringWithFormat:@"%.f",count];
        self.totalprice.text =[NSString stringWithFormat:@"¥%.f",total];
        [self updata];
        return [self.newarray count];
    }else{
        count=[[[self.data objectForKey:@"product"] objectForKey:@"productcount"]floatValue];
        total=[[[self.data objectForKey:@"product"] objectForKey:@"price"]floatValue];
        if([self.data objectForKey:@"product"]){
            [self.newarray addObject:[self.data objectForKey:@"product"]];
        }
        self.totalCount.text =[NSString stringWithFormat:@"%.f",count];
        self.totalprice.text =[NSString stringWithFormat:@"¥%.f",total];
        [self updata];
        return [self.newarray count];
    }
    
    
    
    return [self.data count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 170;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SpaceHotPointDetailCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellIdentiflter"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    id file =[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"thumb400_jpg"];
    [AppData loadImage:file view:cell.imageview];
    cell.nameView.text=[NSString stringWithFormat:@"%@",[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"productname"]];
    cell.nameView2.text=[NSString stringWithFormat:@"%@",[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"productname"]];
    cell.labelView.text=[NSString stringWithFormat:@"%@",[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"content"]];
    cell.specView.text=[NSString stringWithFormat:@"%@",[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"size"]];
    id tp = [self getBrandid:[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"cateid"]];
    if([tp isKindOfClass:NSDictionary.class]){
        cell.classView.text=[tp objectForKey:@"catename"];
    }
    id info = [[self.newarray objectAtIndex:indexPath.row] objectForKey:@"model_info"];
    if (info) {
        id m =[[info objectForKey:@"model"] objectForKey:@"material"];
        if(m)
        {
            cell.materialView.text=[[m firstObject] objectForKey:@"materialname"];
            
        }
    }
    cell.colorView.text=@"";
    //
    cell.priceView.text=[NSString stringWithFormat:@"¥%@",[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"price"]];
    cell.countView.text=[NSString stringWithFormat:@"x%@",[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"productcount"]];
    cell.nameView2.hidden = YES;
    cell.labelView.hidden = YES;
    cell.colorView.hidden = NO;
    cell.materialView.hidden = NO;
    cell.classView.hidden = NO;
    cell.specView.hidden = NO;
    cell.view.hidden = NO;
    cell.guige.hidden = NO;
    cell.pinlei.hidden = NO;
    cell.caizhi.hidden = NO;
    cell.yanse.hidden = NO;
    if([[[self.newarray objectAtIndex:indexPath.row] objectForKey:@"temp_hardpacked"] intValue]==1&&isEmpty(file)){
        cell.nameView2.hidden = NO;
        cell.labelView.hidden = NO;
        
        cell.nameView.hidden = YES;
        cell.colorView.hidden = YES;
        cell.materialView.hidden = YES;
        cell.classView.hidden = YES;
        cell.specView.hidden = YES;
        cell.guige.hidden = YES;
        cell.pinlei.hidden = YES;
        cell.caizhi.hidden = YES;
        cell.yanse.hidden = YES;
        cell.view.hidden = YES;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    id data = [self.newarray objectAtIndex:indexPath.row];
    if (data && [[data objectForKey:@"temp_hardpacked"] boolValue] == NO) {
        [AppData productAttribute:data all:NO];
        //
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"ProductCenter" bundle:nil];
        ProductDetailCtrl *detail = [story instantiateViewControllerWithIdentifier:@"ProductDetailCtrl"];
        [detail setData:data];
        //
        [self presentViewController:detail animated:YES completion:nil];
    }
}
//
-(NSString*)dictionaryToSql:(NSDictionary*)dictionary from:(NSString*)from{
    NSArray *fields = [[TMSQLite shareInstance] query:[NSString stringWithFormat:@"PRAGMA table_info(%@)",from]];
    if (fields) {
        NSMutableArray *keys = [NSMutableArray array];
        NSMutableArray *vals = [NSMutableArray array];
        for (id tmp in fields) {
            id key = [tmp objectForKey:@"name"];
            id value = [dictionary valueForKey:key];
            if (value && [NSNull null] != value) {
                if ([NSJSONSerialization isValidJSONObject:value]){
                    value = [TMJSON stringify:value];
                }
                if ([value isKindOfClass:[NSString class]]) {
                    NSString *str = [value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
                    [vals addObject:[NSString stringWithFormat:@"'%@'",str]];
                }else{
                    [vals addObject:value];
                }
                [keys addObject:[NSString stringWithFormat:@"'%@'",key]];
            }
        }
        if (keys.count == vals.count && keys.count > 0) {
            id key = [keys componentsJoinedByString:@","];
            id value = [vals componentsJoinedByString:@","];
            return [NSString stringWithFormat:@"REPLACE INTO %@ (%@) VALUES (%@)", from, key, value];
        }
    }
    return nil;
}
- (id)getBrandid:(id)Brandid
{
    
    if ([[UIDevice currentDevice] network] != UIDeviceNetworkNone)
    {
        [[[TMSQLite shareInstance] transaction] begin];
        id user = [TMGlobal valueForKey:@"user"];
        if (user)
        {
            NSString *tmp = [NSString stringWithFormat:@"%@?n=api&a=product&c=product_cate&id=%@&token=%@",AppDataRoot,Brandid,[user objectForKey:@"utoken"]];
            NSURL *url = [NSURL URLWithString:tmp];
            TMLoader *loader = [TMLoader load:[TMRequest requestWithURL:url data:nil] delegate:nil cache:1];
            if (loader)
            {
                NSString *json = [[NSString alloc ] initWithData:loader.data encoding:NSUTF8StringEncoding];
                id dat = [TMJSON parse:json];
                if([dat count]==0)
                {
                    return nil;
                }
                //
                
                if([dat isKindOfClass:NSMutableDictionary.class])
                {
                    NSString *sql = [self dictionaryToSql:dat from:@"e360_product_cate"];
                    [[TMSQLite shareInstance] query:sql];
                }
                //
            }
        }
        [[[TMSQLite shareInstance] transaction] commit];
    }
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    NSString *sql = [NSString stringWithFormat:@"SELECT *FROM e360_product_cate WHERE id=%@ ", Brandid];
    id items = [[TMSQLite shareInstance] query:sql];
    dic = [items firstObject];
    
    
    return dic;
}

@end

//
@implementation SpaceIdeaView
-(void)viewDidLoad {
    [super viewDidLoad];
    self.textView.userInteractionEnabled = NO;
    if(self.data!=[NSNull null])
    {
        self.textView.text =[NSString stringWithFormat:@"%@",self.data];
    }
    
}
- (IBAction)closeTouch:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
//
@implementation SpaceEditController
-(void)viewDidLoad {
    [super viewDidLoad];
    //
    self.allData = [[NSMutableArray alloc]init];
    self.allroomDic =[[NSMutableDictionary alloc]init];
    self.pointroomDic =[[NSMutableDictionary alloc]init];
    //
    [self.addScheme setHidden:self.type != 1];
    [self.addScheme addTarget:self action:@selector(addScheme:) forControlEvents:UIControlEventTouchUpInside];
    self.buttonView1.tag=1;self.buttonView2.tag=2;self.buttonView3.tag=3;self.buttonView4.tag=4;
    [self.roomView addTarget:self action:@selector(roomViewTouch:) forControlEvents:UIControlEventTouchUpInside];
    //
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvents:)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 2; //tap次数
    singleFingerOne.delegate = self;
    [self.layerView addGestureRecognizer:singleFingerOne];
    //
    UITapGestureRecognizer *single = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingle:)];
    single.numberOfTouchesRequired = 1; //手指数
    single.numberOfTapsRequired = 1; //tap次数
    single.delegate = self;
    [self.tipsView addGestureRecognizer:single];
    //
    [self setSource:self.source];
}
-(void)setSource:(NSMutableArray *)source{
    [self.prototype setValue:source forKey:@"source"];
    //
    if (self.source && self.isViewLoaded) {
        if(self.source2 && [self.source2 count]>0){
            NSString *tmp = [AppData getPath:[self.source2 objectForKey:@"pic"]];
            TMLoader *loader = [TMLoader load:[TMRequest requestWithURL:[NSURL URLWithString:tmp] data:nil] name:[self.source2 objectForKey:@"pic"] delegate:nil cache:2];
            UIImage *image = [[UIImage alloc]initWithContentsOfFile:loader.file];
            UIImageView *img = [[UIImageView alloc] initWithImage:image];
            if(img){
                float ts = MIN(self.mapView.frame.size.width/image.size.width, self.mapView.frame.size.height/image.size.height);
                float th = image.size.height * ts;
                float tw = image.size.width * ts;
                float tx = (self.mapView.frame.size.width-tw)/2;
                float ty = (self.mapView.frame.size.height-th)/2;
                img.frame = CGRectMake(15+tx, 10+ty, tw-30, th-20);
                img.alpha=0.8;
                [self.mapView addSubview:img];
                //
                for(int i=0;i<[self.source count];i++){
                    id item =[self.source objectAtIndex:i];
                    float tp = tw/600;
                    //
                    UIButton *tips=[[UIButton alloc]initWithFrame:CGRectMake([[item objectForKey:@"posx"] floatValue]*tp, [[item objectForKey:@"posy"] floatValue]*tp, 24, 29)];
                    [self.mapView addSubview:tips];
                    [tips setImage:[UIImage imageNamed:@"btn_Estate_Location_nor.png"] forState:UIControlStateNormal];
                    [tips setImage:[UIImage imageNamed:@"btn_Estate_Location_sel.png"] forState:UIControlStateSelected];
                    [tips addTarget:self action:@selector(mapButtonClick:) forControlEvents:UIControlEventTouchUpInside];
                    tips.tag = [[item objectForKey:@"sort"] integerValue]+5000;
                    //
                }
                if([self.source count]>0){
                    UIButton *b=(UIButton *)[self.mapView viewWithTag:[[[self.source objectAtIndex:self.roomID] objectForKey:@"sort"] intValue]+5000];
                    b.selected = YES;
                }
            }
        }
        //
        [self getData];
    }
}
-(NSMutableArray *)source{
    return [self.prototype valueForKey:@"source"];
}
//
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)addScheme:(UIButton*)sender{
    if (self.onSelected0) {
        NSMutableDictionary *temp = [NSMutableDictionary dictionaryWithDictionary:self.data];
        [temp setValue:self.bigData forKey:@"products"];
        [temp setValue:[NSNumber numberWithFloat:total_price] forKey:@"price"];
        [temp setValue:[NSNumber numberWithFloat:self.classids] forKey:@"classids"];
        self.onSelected0(self, temp);
    }
}
-(void)mapButtonClick:(UIButton *)sender{
    if([self.source count]>0){
        for(int i=0;i<[self.source count];i++){
            UIButton *b=(UIButton *)[self.mapView viewWithTag:[[[self.source objectAtIndex:i] objectForKey:@"sort"] intValue]+5000];
            b.selected = NO;
        }
    }
    sender.selected = YES;
    if([self.source count]>0){
        for(int s=0;s<[self.source count];s++){
            if([[[self.source objectAtIndex:s] objectForKey:@"sort"] intValue]==sender.tag-5000){
                self.roomID=s;
            }
        }
    }
    [self changRoom];
}
-(void)getData{
    self.pointID_yz=0;
    self.pointID = 0;
    self.tipsView.hidden = YES;
    self.DicIndexPath =[NSMutableDictionary dictionary];
    self.DicIndexPath2 =[NSMutableDictionary dictionary];
    self.dic1 =[NSMutableDictionary dictionary];
    self.dic2 =[NSMutableDictionary dictionary];
    self.tempArray = [[NSMutableDictionary alloc]init];
    self.pano = [NSMutableDictionary dictionary];
    self.data = [NSDictionary dictionary];
    self.roomDic =[NSMutableDictionary dictionary];
    //
    self.pointDic =[NSMutableDictionary dictionary];
    self.typepointDic=[NSMutableDictionary dictionary];
    self.typepointDic1=[NSMutableDictionary dictionary];
    //
    if([self.source isKindOfClass:NSMutableArray.class]){
        NSArray *sort=[self.source sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            if ([obj1[@"sort"] floatValue] > [obj2[@"sort"] floatValue]) {
                return NSOrderedDescending;
            }
            if ([obj1[@"sort"] floatValue] < [obj2[@"sort"] floatValue]) {
                return NSOrderedAscending;
            }
            return NSOrderedSame;
        }];
        [self.source removeAllObjects];
        [self.source addObjectsFromArray:sort];
        //
        if([self.source count]>0){
            [self.roomView setTitle:[NSString stringWithFormat:@"  %@",[[self.source objectAtIndex:self.roomID] objectForKey:@"roomname"]] forState:UIControlStateNormal];
        }
    }
    //
    self.titleView.text = self.titleName;
    self.layerView.tipsView2.hidden = YES;
    self.layerView.tipsView.hidden = YES;
    self.layerView.lableView.hidden = YES;
    [self.layerView reset];
    //
    if([self.source isKindOfClass:NSMutableDictionary.class]){
        self.animationView.hidden = YES;
        self.roomView.hidden = YES;
    }else{
        self.animationView.hidden = NO;
        self.roomView.hidden = NO;
    }
    //
    while ([MBProgressHUD hideHUDForView:self.view animated:NO]);
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        if(self.source){
            if([self.source isKindOfClass:NSMutableDictionary.class]){
                NSMutableDictionary *dic =(NSMutableDictionary *)self.source;
                id suitID = [dic objectForKey:@"id"];
                //
                [self.allData removeAllObjects];
                [self.bigData removeAllObjects];
                id user = [TMGlobal valueForKey:@"user"];
                if (user) {
                    self.data = [self getAllSuit:suitID];
                    if(self.data){
                        [self.allData addObject:self.data];
                        [self getListData];
                    }
                }
            }else if ([self.source count] > 0){
                //0:默认功能间  0:默认套餐
                if([self.allData count] == 0){
                    for(int i=0;i<[self.source count];i++){
                        if([[[self.source objectAtIndex:i] objectForKey:@"mjt_house_room_suit"] count]>0){
                            id ID = [[[[self.source objectAtIndex:i] objectForKey:@"mjt_house_room_suit"] firstObject] objectForKey:@"suitid"];
                            id user = [TMGlobal valueForKey:@"user"];
                            if (user) {
                                self.data = [self getAllSuit:ID];
                                if(self.data){
                                    [self.allData addObject:self.data];
                                }
                            }
                        }
                    }
                    if([self.allData count]>0){
                        self.data = [self.allData objectAtIndex:self.roomID];
                        [self getListData];
                    }
                }else{
                    if([self.allData count]>0){
                        if(self.roomID<[self.allData count]){
                            self.data = [self.allData objectAtIndex:self.roomID];
                            [self getListData];
                        }
                    }
                }
                //地图上的点
                if([self.allroomDic count]>0){
                    self.roomDic = [self.allroomDic objectForKey:[NSNumber numberWithInteger:self.roomID]];
                    if(self.roomDic==nil){
                        self.roomDic =[NSMutableDictionary dictionary];
                    }
                }
                if([self.pointroomDic count]>0){
                    self.pointDic = [self.pointroomDic objectForKey:@(self.roomID)];
                }
            }
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if([self.data count]>0){
                //背景
                if(self.count==1){
                    [self.layerView setImage:[self.data objectForKey:@"bgpic2"] index:10000];
                }else{
                    [self.layerView setImage:[self.data objectForKey:@"bgpic1"] index:10000];
                }
                //
                self.photo = [TMJSON parse:[self.data objectForKey:@"photos"]];
                if(isEmpty([self.pano objectForKey:@"back"])){
                    self.PanoView.enabled = NO;
                    [self.pano removeAllObjects];
                }else{
                    self.PanoView.enabled = YES;
                    [self.pano setValue:[self.data objectForKey:@"front"] forKey:@"front"];
                    [self.pano setValue:[self.data objectForKey:@"back"] forKey:@"back"];
                    [self.pano setValue:[self.data objectForKey:@"left"] forKey:@"left"];
                    [self.pano setValue:[self.data objectForKey:@"right"] forKey:@"right"];
                    [self.pano setValue:[self.data objectForKey:@"up"] forKey:@"up"];
                    [self.pano setValue:[self.data objectForKey:@"down"] forKey:@"down"];
                    [self.pano setValue:[self.data objectForKey:@"house_sample_room_class"] forKey:@"house_sample_room_class"];
                    [self.pano setValue:[self.data objectForKey:@"house_sample_room_class"] forKey:@"house_sample_room_match"];
                }
                //
                [self.buttonView1 sendActionsForControlEvents:UIControlEventTouchUpInside];
                //
                NSMutableArray*pointArray = [[NSMutableArray alloc]init];
                id point = [self.data objectForKey:@"house_sample_room_class_positions"];
                for(id  item in point){
                    if(![[item objectForKey:@"viewtype"] isEqualToString:@"viewpic1"]&&![[item objectForKey:@"viewtype"] isEqualToString:@"viewpic2"]){
                        [pointArray addObject:item];
                    }
                }
                if([pointArray count]>0){
                    [self.pano setValue:pointArray forKey:@"point"];
                }
                [self creatPoint];
            }
            //
            [self.AngleView addTarget:self action:@selector(AngleEvent:) forControlEvents:UIControlEventTouchUpInside];
            [self.LableView addTarget:self action:@selector(LableViewTouch:) forControlEvents:UIControlEventTouchUpInside];
            [self.animationView addTarget:self action:@selector(animationViewTouch:) forControlEvents:UIControlEventTouchUpInside];
            [self.MagicView addTarget:self action:@selector(MagicViewClick:) forControlEvents:UIControlEventTouchUpInside];
            //
            UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] init];
            [swipeUp addTarget:self action:@selector(gestureRecognizerHandle:)];
            [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
            [self.layerView addGestureRecognizer:swipeUp];
            //
            UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] init];
            [swipeDown addTarget:self action:@selector(gestureRecognizerHandle:)];
            [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
            [self.layerView addGestureRecognizer:swipeDown];
            //
            if(![self.source isKindOfClass:NSMutableDictionary.class]){
                if([self.source count]>0){
                    for(int i=0;i<[self.source count];i++){
                        UIButton *b=(UIButton *)[self.mapView viewWithTag:[[[self.source objectAtIndex:i] objectForKey:@"sort"] intValue]+5000];
                        b.selected = NO;
                    }
                }
                if (self.roomID < [self.source count]) {
                    int a = [[[self.source objectAtIndex:self.roomID] objectForKey:@"sort"] intValue];
                    UIButton *btn = (UIButton *)[self.mapView viewWithTag:a+5000];
                    btn.selected = YES;
                }
            }
            
            //
            [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(closeTouch) name:@"closeTouch" object:nil];
            
            //
            //空间是否收藏过
            NSDictionary *client = [TMGlobal valueForKey:@"client"];
            if([self.source isKindOfClass:NSMutableDictionary.class]){
                id tmpsd=self.source;
                [tmpsd setValue:@"suit" forKey:@"t"];
                id fav = [AppData userHaveFavorite:tmpsd client:client];
                if (fav) {
                    self.collectView.selected = YES;
                }else{
                    self.collectView.selected = NO;
                }
            }else{
                if (self.roomID < [self.source count]) {
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    id tmpsd=[[[self.source objectAtIndex:self.roomID] objectForKey:@"mjt_house_room_suit"] firstObject];
                    [dic setValue:[tmpsd objectForKey:@"suitid"] forKey:@"id"];
                    [dic setValue:@"suit" forKey:@"t"];
                    id fav = [AppData userHaveFavorite:dic client:client];
                    if (fav) {
                        self.collectView.selected = YES;
                    }else{
                        self.collectView.selected = NO;
                    }
                }
            }
            [self getjson];
            [self updata];
        });
    });
}
-(void)getjson{
    id tps = nil;
    id json = nil;
    if([self.source isKindOfClass:NSMutableDictionary.class]){
        tps = self.source;
        if([tps objectForKey:@"json"]){
            json = [TMJSON parse:[tps objectForKey:@"json"]];
            if (json) {
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                for (NSString *key in [json allKeys]) {
                    id val = [json objectForKey:key];
                    if (val && [val isKindOfClass:NSDictionary.class]) {
                        if ([val objectForKey:@"row"]) {
                            NSInteger row = [[val objectForKey:@"row"] integerValue];
                            NSInteger section = [[val objectForKey:@"section"] integerValue];
                            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
                            [dic setValue:indexPath forKey:key];
                        }else{
                            NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
                            for (id key2 in [val allKeys]) {
                                id val2 = [val objectForKey:key2];
                                if (val2 && [val2 isKindOfClass:NSDictionary.class]) {
                                    NSInteger row = [[val2 objectForKey:@"row"] integerValue];
                                    NSInteger section = [[val2 objectForKey:@"section"] integerValue];
                                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
                                    [dic2 setValue:indexPath forKey:key2];
                                }
                            }
                            [dic setValue:dic2 forKey:key];
                        }
                    }
                }
                if(dic){
                   self.roomDic = dic;
                }
            }
        }
    }
}
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender{
    if ([TMGlobal valueForKey:@"client"]&&([identifier isEqualToString:@"favoriteSegue"]||[identifier isEqualToString:@"cartSegue"])) {
        if ([identifier isEqualToString:@"favoriteSegue"]) {
            [self collectViewTouch:sender];
        }
        return NO;
    }
    return YES;
}

-(void)getListData{
    //
    id suitname=nil;
    id suiticon=nil;
    self.bigData = [[NSMutableArray alloc]init];
    for(id dat in self.allData)
    {
        id detail = [dat objectForKey:@"detail"];
        for(id it in detail){
            if([[[it objectForKey:@"parent"] objectForKey:@"classname"] isEqualToString:@"空间"])
            {
                suitname = [[it objectForKey:@"class"] objectForKey:@"classname"];
                suiticon = [[it objectForKey:@"class"] objectForKey:@"pic"];
            }
        }
        NSMutableDictionary *Dictionary = [NSMutableDictionary dictionary];
        id datas=[dat objectForKey:@"house_sample_room_match"];
        if([datas count]>0){
            for( id items in datas)
            {
                if([[items objectForKey:@"house_sample_room_match_class"] count]==0){
                    continue;
                }
                if([[[items objectForKey:@"house_sample_room_match_class"] objectForKey:@"hardpacked"] integerValue]==1)
                {
                    //硬装
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    NSMutableArray *arr = [[NSMutableArray alloc]init];
                    id tp = [items objectForKey:@"product_class"];
                    for(id source in tp){
                        [arr addObject:source];
                    }
                    [dict setValue:arr forKey:@"data"];
                    [dict setValue:@"硬装" forKey:@"name"];
                    [dict setValue:[dat objectForKey:@"id"] forKey:@"suitid"];
                    [dict setValue:[dat objectForKey:@"pic"] forKey:@"pic"];
                    [dict setValue:[NSNumber numberWithInt:0] forKey:@"hardpacked"];
                    [Dictionary setValue:dict forKey:@"yz"];
                }else{
                    //软装
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    NSMutableArray *arr = [[NSMutableArray alloc]init];
                    id tp = [items objectForKey:@"product_class"];
                    for(id source in tp){
                        [arr addObject:source];
                    }
                    [dict setValue:arr forKey:@"data"];
                    [dict setValue:@"软装" forKey:@"name"];
                    [dict setValue:[dat objectForKey:@"pic"] forKey:@"pic"];
                    [dict setValue:[dat objectForKey:@"id"] forKey:@"suitid"];
                    [dict setValue:[NSNumber numberWithInt:0] forKey:@"hardpacked"];
                    [Dictionary setValue:dict forKey:@"rz"];
                }
            }
            
        }
        [Dictionary setValue:suiticon forKey:@"suiticon"];
        [Dictionary setValue:suitname forKey:@"suitname"];
        [self.bigData addObject:Dictionary];
    }
    
    NSLog(@"%ld    ===    %@",(long)[[self.bigData firstObject] count],[self.bigData firstObject]);
}

-(NSString*)hashRequest:(NSString*)request{
    if (request) {
        const char *cStr = [request UTF8String];
        unsigned char result[CC_MD5_DIGEST_LENGTH];
        CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
        NSMutableString *temp = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
        for(uint i = 0; i < CC_MD5_DIGEST_LENGTH; i++){
            [temp appendFormat:@"%02x",result[i]];
        }
        //
        NSString *src = [temp lowercaseString];
        NSString *ext = [request pathExtension];
        if (ext && [ext length] > 0) {
            return [src stringByAppendingPathExtension:ext];
        }
        return src;
    }
    return @"";
}
-(NSString*)pathForTemporary:(NSString*)path{
    return [[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:path];
}

//


-(void)AngleEvent:(UIButton *)sender{
//    [TMAlert showAtView:self.view image:@"img_PromptAngle.png"];
//
//
//    spaceproductlist.type = 0;
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(allTouch) name:@"allTouch" object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    self.all = 0;
   
    BOOL isp = NO;
    for(int i=0;i<[[self.data objectForKey:@"house_sample_room_class"] count];i++){
        id ts =[[[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:i] objectForKey:@"class_product"];
        for(int j=0;j<[ts count];j++){
            id tp = [[ts objectAtIndex:j] objectForKey:@"angle_pic"] ;
            if([tp count]==1){
                isp = YES;
                break;
            }
            
        }
    }
    
    if(isp){
        [TMAlert showAtView:self.view image:@"img_PromptAngle.png"];
        return;
    }
    
    sender.selected = !sender.selected;
    if(sender.selected){
        self.count = 1;
    }else{
        self.count = 0;
    }
    [self getData];
    [self updata];
}

-(void)updataSelect{
//    self.AngleView.selected = NO;
    self.PanoView.selected = NO;
    self.PhotoView.selected = NO;
    self.IdeaView.selected = NO;
    self.LableView.selected = NO;
    self.ListView.selected = NO;
    self.collectView.selected = NO;
    self.animationView.selected = NO;
}
-(void)LableViewTouch:(UIButton *)sneder{
//    [self updataSelect];
//    self.LableView.selected = YES;
    self.layerView.lableView.hidden=!self.layerView.lableView.hidden;
}
-(void)collectViewTouch:(UIButton *)sneder{
    
    NSLog(@"%@",self.roomDic);
    self.layerView.tipsView.hidden = YES;
    self.layerView.tipsView2.hidden = YES;
    //
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.layerView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *GraproomImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //
    NSData *dat=UIImagePNGRepresentation(GraproomImage);
    UIImageView *pic=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    UIImage *img=[[UIImage alloc] initWithData:dat];
    pic.image=img;

    //
    NSDictionary *client = [TMGlobal valueForKey:@"client"];
    if([self.source isKindOfClass:NSMutableDictionary.class]){
        id tp = self.source;
        [tp setValue:@"suit" forKey:@"t"];
        [tp setValue:self.roomDic forKey:@"json"];
        [tp setValue:img forKey:@"pic"];
        //
        id fav = [AppData userHaveFavorite:tp client:client];
        if (fav) {
            [sneder setSelected:NO];
        }else{
            [sneder setSelected:YES];
        }
        //
        if(sneder.selected){
            if ([AppData userEditFavorite:tp client:client])
            {
                [TMAlert showAtView:self.view image:@"img_Prompt_Favorites_OK.png"];
            }
        }else{
            if ([AppData userDeleteFavorite:tp client:client]) {
                [TMAlert showAtView:self.view image:@"img_Prompt_Favorites_Cancel.png"];
            }
        }
    }else{
        if([self.source count]>0){
            id cid = [[[self.source objectAtIndex:self.roomID] objectForKey:@"mjt_house_room_suit"] firstObject];
            if (cid) {
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                [dic setValue:[cid objectForKey:@"suitid"] forKey:@"id"];
                [dic setValue:@"suit" forKey:@"t"];
                [dic setValue:self.roomDic forKey:@"json"];
                [dic setValue:img forKey:@"pic"];
                //
                id fav = [AppData userHaveFavorite:dic client:client];
                if (fav) {
                    [sneder setSelected:NO];
                }else{
                    [sneder setSelected:YES];
                }
                //
                if(sneder.selected){
                    if ([AppData userEditFavorite:dic client:client]){
                        [TMAlert showAtView:self.view image:@"img_Prompt_Favorites_OK.png"];
                    }
                }else{
                    if ([AppData userDeleteFavorite:dic client:client]) {
                        [TMAlert showAtView:self.view image:@"img_Prompt_Favorites_Cancel.png"];
                    }
                }
            }
        }
    }
}

-(void)showMovie:(id)path{
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        NSURL *url = [NSURL fileURLWithPath:path];
        if (url) {
            AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
            [controller setVideoGravity:AVLayerVideoGravityResizeAspect];
            [controller setPlayer:[[AVPlayer alloc] initWithURL:url]];
            [controller setShowsPlaybackControls:NO];
            //
            [self addChildViewController:controller];
            [self.view addSubview:controller.view];
            [controller.view setFrame:self.view.bounds];
            [controller.view setHidden:YES];
            [controller.player play];
            //
            __weak SpaceEditController *this = self;
            __weak AVPlayerViewController *weak = controller;
            [controller.player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(0.04, NSEC_PER_SEC) queue:NULL usingBlock:^(CMTime time){
                if (weak.readyForDisplay && weak.view.hidden) {
                    [this performSelectorOnMainThread:@selector(changRoom) withObject:nil waitUntilDone:YES];
                    [weak.view setHidden:NO];
                }
                //
                double duration = CMTimeGetSeconds(weak.player.currentItem.duration);
                double current = CMTimeGetSeconds(weak.player.currentTime);
                if (current >= duration) {
                    [weak.view removeFromSuperview];
                    [weak removeFromParentViewController];
                }
            }];
        }
    }
}

-(void)animationViewTouch:(UIButton *)sneder
{
    if(self.roomID==[self.source count]-1){
        return;
    }
    self.roomID++;
    if([self.source isKindOfClass:NSMutableDictionary.class]){
        return;
    }
    if([self.source count]==0){
        return;
    }
    __weak SpaceEditController *blockSelf = self;
    [MBProgressHUD showHUDAddedTo:blockSelf.view animated:YES];
    //
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSString *tmp = [AppData getPath:[[self.source objectAtIndex:self.roomID] objectForKey:@"video"]];
        [TMLoader load:[TMRequest requestWithURL:[NSURL URLWithString:tmp] data:nil] name:[[self.source objectAtIndex:self.roomID] objectForKey:@"video"] delegate:nil cache:2];
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
            NSString *file=pathForLibrary([[self.source objectAtIndex:self.roomID] objectForKey:@"video"]);
            [self showMovie:file];
        });
    });
}

-(void)changRoom{
    self.data = nil;
    [self.newarray removeAllObjects];
    //刷新数据
    [self getData];
    //[self updata];
}
-(void)updata{
    if([self.data count]>0){
        ruanzhuang.roomDic = [self.allroomDic objectForKey:@(self.roomID)];
        ruanzhuang.index = @"1";
        ruanzhuang.data = [self.data objectForKey:@"house_sample_room_match"];
        [ruanzhuang updata];
        //
        [self updata_dp];
        //
        yingzhuang.roomDic = [self.allroomDic objectForKey:@(self.roomID)];
        yingzhuang.index = @"3";
        yingzhuang.data = [self.data objectForKey:@"house_sample_room_match"];
        [yingzhuang updata];
        //硬装
        [self updata_yzdp];
    }
    self.PropertyListView.hidden = NO;
    self._height.constant = self.PropertyListView.frame.size.height;
    [self.view updateConstraintsIfNeeded];
}
-(void)gestureRecognizerHandle:(UISwipeGestureRecognizer*)sender{
    self.PropertyListView.hidden = NO;
    if (sender && sender.direction==UISwipeGestureRecognizerDirectionUp){
        self._height.constant = 0;
    }else if (sender && sender.direction==UISwipeGestureRecognizerDirectionDown){
        self._height.constant = self.PropertyListView.frame.size.height;
    }
    [self.view updateConstraintsIfNeeded];
    [UIView beginAnimations:nil context:nil];
    [self.view layoutIfNeeded];
    [UIView commitAnimations];
}

//单击
- (void)handleSingle:(UITapGestureRecognizer *)sender
{
    self.tipsView.hidden = YES;
    self.tipsView.alpha = 0;
    self.tipsView.userInteractionEnabled = YES;
}
- (void)handleSingleFingerEvents:(UITapGestureRecognizer *)sender
{
    
    cot++;
    if(cot%2==0){
        cot=0;
        [UIView beginAnimations:nil context:nil];
        [self.menuView setFrame:CGRectMake(0, 0, self.menuView.frame.size.width, self.menuView.frame.size.height)];
        [self.topView setFrame:CGRectMake(0, self.view.frame.size.height-self.topView.frame.size.height, self.topView.frame.size.width, self.topView.frame.size.height)];
        [self.bottomView setFrame:CGRectMake(0, self.view.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height)];
        self.mapView.hidden = YES;
        [UIView commitAnimations];
    }else{
        [UIView beginAnimations:nil context:nil];
        [self.menuView setFrame:CGRectMake(0, 0-self.menuView.frame.size.height, self.menuView.frame.size.width, self.menuView.frame.size.height)];
        [self.topView setFrame:CGRectMake(0, self.view.frame.size.height, self.topView.frame.size.width, self.topView.frame.size.height)];
        
        [self.bottomView setFrame:CGRectMake(0, self.view.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height)];
        self.mapView.hidden = YES;
        self.PropertyListView.hidden = YES;
        [UIView commitAnimations];
    }
}
-(void)MagicViewClick:(UIButton *)sender{
    [UIView beginAnimations:nil context:nil];
    self.tipsView.hidden = NO;
    [self.bottomView setFrame:CGRectMake(0, self.view.frame.size.height-self.bottomView.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height)];
    [self.topView setFrame:CGRectMake(0, self.view.frame.size.height, self.topView.frame.size.width, self.topView.frame.size.height)];
    [UIView commitAnimations];
}
-(void)updataBigData:(id)dat key:(id)key sort:(id)sort
{
    if([self.bigData count]>0&&[self.bigData count]>self.roomID){
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSMutableArray* item =[[[self.bigData objectAtIndex:self.roomID] objectForKey:key] objectForKey:@"data"] ;
        for(int i=0;i<[item count];i++)
        {
            if([[[item objectAtIndex:i] objectForKey:@"sort"] integerValue] == [sort integerValue]){
                
                if(dat)[dic setValue:dat forKey:@"class_product"];
                if(dic){
                    [dic setValue:sort forKey:@"sort"];
                    [item replaceObjectAtIndex:i withObject:dic];
                }
                   
            }
            if([sort integerValue]==0){
                if(dat)[dic setValue:dat forKey:@"class_product"];
                if(dic){
                    [dic setValue:sort forKey:@"sort"];
                    [item replaceObjectAtIndex:i withObject:dic];
                }
                
            }
        }
        
        NSLog(@"%@",[self.bigData objectAtIndex:self.roomID]);
        [self getTotalprice];
    }
    
}
-(void)getTotalprice{
    total_price =0;
    id data = [self.bigData objectAtIndex:self.roomID];
    if(data){
        id tp= [[data objectForKey:@"rz"] objectForKey:@"data"];
        for(int j=0;j<[tp count];j++){
            total_price+=[[[[[[tp objectAtIndex:j] objectForKey:@"class_product"] firstObject] objectForKey:@"product"] objectForKey:@"price"] integerValue];
        }
        //
        id tps= [[data objectForKey:@"yz"] objectForKey:@"data"];
        for(int k=0;k<[tps count];k++){
            total_price+=[[[[[[tps objectAtIndex:k] objectForKey:@"class_product"] firstObject]  objectForKey:@"product"] objectForKey:@"price"] integerValue];
        }
    }
    if([self.source isKindOfClass:NSMutableDictionary.class]){
        if(self.type==1){
            self.dis.constant = 142;
        }else{
            self.dis.constant = 30;
        }
        
    }else{
        self.dis.constant = 142;
    }
    [self.view updateConstraintsIfNeeded];
    [UIView beginAnimations:nil context:nil];
    [self.view layoutIfNeeded];
    [UIView commitAnimations];
    self.totalprice.text = [NSString stringWithFormat:@"空间总价：￥%.2f",total_price];
}


-(void)displayLayer:(id )dic index:(id)index layerid:(NSInteger)layerid{
    //角度2
//    if(self.count==1){
//        return;
//    }
    //显示图层
    //单品
    if(dic && [dic isKindOfClass:NSArray.class]){
        id pic=[[dic objectAtIndex:self.count] objectForKey:@"pic"];
        if (pic) {
            if(index){
                SpacePropertyContainer * con = (SpacePropertyContainer*)index;
                if(layerid==2){
                    NSLog(@"%@",con.data);
                    [self.layerView setImage:pic index:[con.sort intValue]];
                    [self updataBigData:con.data key:@"rz" sort:con.sort];
                }
                if(layerid==4){
                    [self.layerView setImage:pic index:[con.sort intValue]];
                    [self updataBigData:con.data key:@"yz" sort:con.sort];
                }
            }
            
        }
    }
    NSMutableArray *tp = [[NSMutableArray alloc]init];
    if([self.data count]>0){
        if(layerid==3)
        {
            id it=[self.data objectForKey:@"house_sample_room_class"];
            for(int i=0;i<[it count];i++){
                id itd = [it objectAtIndex:i];
                if([[itd objectForKey:@"hardpacked"] intValue]==1){
                    [tp addObject:[NSNumber numberWithInt:i]];
                }
            }
        }
    }
    //套餐
    if([dic isKindOfClass:NSDictionary.class]){
        NSInteger count=[[dic objectForKey:@"product_class"] count];
        for(int i=0;i<count;i++){
            if([[[[dic objectForKey:@"product_class"] objectAtIndex:i] objectForKey:@"class_product"] count]>0){
                id item =[[[[dic objectForKey:@"product_class"] objectAtIndex:i] objectForKey:@"class_product"] firstObject];
                id tp =[[[dic objectForKey:@"product_class"] objectAtIndex:i] objectForKey:@"class_product"];
                NSLog(@"productid  ==  %@",[item objectForKey:@"productid"]);
                id pic=[[[item objectForKey:@"angle_pic"] objectAtIndex:self.count] objectForKey:@"pic"];
                NSInteger sort =[[[[dic objectForKey:@"product_class"] objectAtIndex:i] objectForKey:@"sort"] intValue];
                NSLog(@"  ==  %ld",(long)sort);
                if (pic) {
                    if(layerid==1){
                        [self.layerView setImage:pic index:sort];
                        [self updataBigData:tp key:@"rz" sort:[NSNumber numberWithInteger:sort]];
                    }
//                    if(sort==2){
//                        [self.layerView setImage:pic index:sort];
//                        [self updataBigData:tp key:@"rz" sort:[NSNumber numberWithInteger:sort]];
//                    }
                    if(layerid==3){
                        [self.layerView setImage:pic index:sort];
                        [self updataBigData:tp key:@"yz" sort:[NSNumber numberWithInteger:sort]];
                    }
//                    if(sort==4){
//                        [self.layerView setImage:pic index:sort];
//                        [self updataBigData:tp key:@"yz" sort:[NSNumber numberWithInteger:sort]];
//                    }
                }
            }
        }
    }
}

-(void)tipsLableTouch:(ButtonLable *)sender{
    self.pointLableID=sender.tag;
    self.lableIndex = [sender.index integerValue]-1000;
    [self.tempButton sendActionsForControlEvents:UIControlEventTouchUpInside];
}
-(void)tipsTouch:(ButtonLable *)sender{
    NSMutableArray*LayerPointArray = [[NSMutableArray alloc]init];
    LayerPointArray = [self getpointArray];
    for(int i=0;i<[LayerPointArray count];i++){
        ButtonLable *btn = (ButtonLable *)[self.layerView.tipsView viewWithTag:i+1000];
        btn.selected = NO;
    }
    sender.selected = YES;
    self.pointID=sender.tag-1000;
    self.classid = [sender.index integerValue];
    [self.typepointDic setObject:[NSNumber numberWithInteger:self.pointID] forKey:[NSNumber numberWithInteger:self.pointID]];
    if(self.pointDic==nil){
        self.pointDic = [NSMutableDictionary dictionary];
    }
    if(self.typepointDic)[self.pointDic setValue:self.typepointDic forKey:@"2"];
    if(self.pointDic)[self.pointroomDic setObject:self.pointDic forKey:@(self.roomID)];
    //
    self.PropertyListView.hidden = NO;
    self._height.constant = 0;
    [self.view updateConstraintsIfNeeded];
    [UIView beginAnimations:nil context:nil];
    [self.view layoutIfNeeded];
    [UIView commitAnimations];
    //
    //[self updata_dp];
    if(ruanzhuang_danpin){
        ruanzhuang_danpin.roomDic=[self.allroomDic objectForKey:@(self.roomID)];
        ruanzhuang_danpin.index=@"2";
        
        ruanzhuang_danpin.pointDic = [self.pointroomDic objectForKey:@(self.roomID)];
        id item = [self.data objectForKey:@"house_sample_room_class"];
        for(int i=0;i<[item count];i++){
            if([[[item objectAtIndex:i] objectForKey:@"id"] integerValue] == self.classid){
                self.pointID = i;
            }
        }
        ruanzhuang_danpin.pointID = self.pointID;
        ruanzhuang_danpin.data = [[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:self.pointID] ;
        [ruanzhuang_danpin updata];
    }

}
-(void)tipsTouch_yz:(ButtonLable *)sender{
    NSMutableArray*LayerPointArray = [[NSMutableArray alloc]init];
    LayerPointArray = [self getpointArray];
    for(int i=0;i<[LayerPointArray count];i++){
        ButtonLable *btn = (ButtonLable *)[self.layerView.tipsView2 viewWithTag:i+1000];
        btn.selected = NO;
    }
    sender.selected = YES;
    self.pointID_yz=sender.tag-1000;
    self.indexID = [sender.index intValue]-1000;
//    id
    for(int i=0;i<[[self.data objectForKey:@"house_sample_room_class"] count];i++){
        if([[[[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:i] objectForKey:@"id"] intValue]==[[[LayerPointArray objectAtIndex:self.pointID_yz] objectForKey:@"classid"] intValue]){
            self.pointID_yz = i;
            //self.indexID = i;
        }
    }
    
    NSLog(@"%@",[[LayerPointArray objectAtIndex:self.pointID_yz] objectForKey:@"classid"]);
    
    [self.typepointDic1 setObject:[NSNumber numberWithInteger:self.pointID_yz] forKey:[NSNumber numberWithInteger:self.indexID]];
    if(self.typepointDic1)[self.pointDic setValue:self.typepointDic1 forKey:@"4"];
    if(self.pointDic==nil){
        self.pointDic = [NSMutableDictionary dictionary];
    }
    if(self.pointDic)[self.pointroomDic setObject:self.pointDic forKey:@(self.roomID)];
    //
    self.PropertyListView.hidden = NO;
    self._height.constant = 0;
    [self.view updateConstraintsIfNeeded];
    [UIView beginAnimations:nil context:nil];
    [self.view layoutIfNeeded];
    [UIView commitAnimations];
    //
    if(yingzhuang_danpin){
        yingzhuang_danpin.roomDic=[self.allroomDic objectForKey:@(self.roomID)];
        yingzhuang_danpin.pointDic = [self.pointroomDic objectForKey:@(self.roomID)];
        yingzhuang_danpin.pointID_yz=self.indexID;
        yingzhuang_danpin.index = @"4";
        yingzhuang_danpin.data = [[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:self.pointID_yz];
        [yingzhuang_danpin updata];
    }
}
//刷新单品列表
-(void)updata_yzdp
{
    if(yingzhuang_danpin){
        if (self.DicIndexPath) {
            yingzhuang_danpin.DicIndexPath=self.DicIndexPath;
            //[self setDicIndexPath:nil];
        }
        //
        id tp = [self.pointroomDic objectForKey:@(self.roomID)];
        if([tp count]>0){
            for(id key in [[tp objectForKey:@"4"] allKeys]){
                yingzhuang_danpin.pointDic=tp;
                yingzhuang_danpin.roomDic=[self.allroomDic objectForKey:@(self.roomID)];
                yingzhuang_danpin.index=@"4";
                yingzhuang_danpin.pointID_yz =[key integerValue];
                self.indexID = [key integerValue];
                NSInteger ID = [[[tp objectForKey:@"4"] objectForKey:key] integerValue];
                yingzhuang_danpin.data = [[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:ID] ;
                [yingzhuang_danpin updata];
            }
        }else{
            yingzhuang_danpin.roomDic=[self.allroomDic objectForKey:@(self.roomID)];
            yingzhuang_danpin.pointDic = nil;
            yingzhuang_danpin.index=@"4";
            //
            if(self.pointID_yz==0){
                id it=[self.data objectForKey:@"house_sample_room_class"];
                for(int i=0;i<[it count];i++){
                    id itd = [it objectAtIndex:i];
                    if([[itd objectForKey:@"hardpacked"] intValue]==1){
                        self.pointID_yz = i;
                        break;
                    }
                }
            }
            
            //
            yingzhuang_danpin.data = [[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:self.pointID_yz] ;
            [yingzhuang_danpin updata];
        }
        
    }
}
-(void)allTouch
{
    self.all = 1;
}
-(void)updata_dp{
    if(ruanzhuang_danpin){
        if (self.DicIndexPath2) {
            ruanzhuang_danpin.DicIndexPath2=self.DicIndexPath2;
        }
        //
        id tp = [self.pointroomDic objectForKey:@(self.roomID)];
        if([tp count]>0){
            ruanzhuang_danpin.pointDic = tp;
            for(id key in [[tp objectForKey:@"2"] allKeys]){
                ruanzhuang_danpin.roomDic=[self.allroomDic objectForKey:@(self.roomID)];
                ruanzhuang_danpin.index=@"2";
                ruanzhuang_danpin.pointID =[key integerValue];
                self.pointID = [key integerValue];
                NSInteger ID = [[[tp objectForKey:@"2"] objectForKey:key] integerValue];
                ruanzhuang_danpin.data = [[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:ID] ;
                [ruanzhuang_danpin updata];
            }
        }else{
            ruanzhuang_danpin.roomDic=[self.allroomDic objectForKey:@(self.roomID)];
            ruanzhuang_danpin.pointDic = nil;
            ruanzhuang_danpin.index=@"2";
            //ruanzhuang_danpin.DicIndexPath2 = self.DicIndexPath2;
//            id item = [self.data objectForKey:@"house_sample_room_class"];
//            for(int i=0;i<[item count];i++){
//                if([[[item objectAtIndex:i] objectForKey:@"id"] integerValue] == self.classid){
//                    self.pointID = i;
//                }
//            }

            ruanzhuang_danpin.data = [[self.data objectForKey:@"house_sample_room_class"] objectAtIndex:self.pointID] ;
            [ruanzhuang_danpin updata];
        }
        
    }
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    //
    SpacePhotoView *photo = [segue destinationViewController];
    if([photo isKindOfClass:SpacePhotoView.class]){
        if([self.photo count] > 0){
            [photo setData:self.photo];
        }
        return;
    }
    //
    SpacePanoController *pano = [segue destinationViewController];
    if([pano isKindOfClass:SpacePanoController.class]){
        pano.DicIndexPath = self.DicIndexPath;
        pano.DicIndexPath2 = self.DicIndexPath2;
        [pano setData:self.pano];
        return;
    }
    //清单
    __weak SpaceEditController *this = self;
    UINavigationController *root = segue.destinationViewController;
    if ([root isKindOfClass:UINavigationController.class]) {
        if ([[root.viewControllers firstObject] isKindOfClass:SpaceProductList.class]) {
            [self updataSelect];
            //
            NSMutableArray *array = [[NSMutableArray alloc]init];
            spaceproductlist = [root.viewControllers firstObject];
            spaceproductlist.type = self.all;
            spaceproductlist.onSelected_productList = ^(id sender, id result){
                this.ListView.selected = NO;
            };
            if([self.source count]>0){
                if([self.source isKindOfClass:NSMutableDictionary.class]){
                    [self.source setValue:[[self.allData firstObject] objectForKey:@"suitname"] forKey:@"roomname"];
                    [array addObject:self.source];
                    spaceproductlist.ID=0;
                    [spaceproductlist setData_left:array];
                }else{
                    spaceproductlist.ID=[NSNumber numberWithInteger:self.roomID];
                    if([self.allData count] == [self.source count]){
                        for(int i=0;i<[self.allData count];i++){
                            id tp = [self.allData objectAtIndex:i];
                            id obj = [self.source objectAtIndex:i];
                            [obj setValue:[tp objectForKey:@"suitname"] forKey:@"suitname"];
                        }
                    }
                    [spaceproductlist setData_left:self.source];
                }
                if([self.bigData count]>0){
                    [spaceproductlist setData_right:self.bigData];
                }
            }
            [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(allTouch) name:@"allTouch" object:nil];
            return;
        }
        if ([[root.viewControllers firstObject] isKindOfClass:SpaceHotPointDetail.class]) {
            SpaceHotPointDetail *HotPointDetail = [root.viewControllers firstObject];
            //
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
            NSMutableArray *array = [[NSMutableArray alloc] init];
            NSMutableArray *array2 = [[NSMutableArray alloc] init];
            //
            id class = nil;
            NSInteger ID = 0;
            //
            class = [[NSMutableArray alloc]init];
            class = [self.data objectForKey:@"house_sample_room_class"];
            //
            for(int i=0;i<[class count];i++){
                if([[[class objectAtIndex:i] objectForKey:@"id"] intValue] == self.pointLableID){
                    ID = i;
                    break;
                }
            }
            id tp =  [class objectAtIndex:ID];
            id temp =[tp objectForKey:@"class_product"];
            //
            for (NSDictionary * obj in temp) {
                if([[obj objectForKey:@"product"] count]>0){
                    NSString *parentid = [[obj objectForKey:@"product"] objectForKey:@"parentid"];
                    NSString *hardpacked = [[obj objectForKey:@"product"] objectForKey:@"temp_hardpacked"];
                    if(parentid){
                        if([hardpacked intValue]==0){
                            if (dic[parentid] == nil) {
                                NSMutableArray *arr = [NSMutableArray array];
                                [arr addObject:obj];
                                dic[parentid] = arr;
                            }else{
                                NSMutableArray *arr = dic[parentid];
                                [arr addObject:obj];
                            }
                        }
                        if([hardpacked intValue]==1){
                            if (dic2[parentid] == nil) {
                                NSMutableArray *arr = [NSMutableArray array];
                                [arr addObject:obj];
                                dic2[parentid] = arr;
                            }else{
                                NSMutableArray *arr = dic2[parentid];
                                [arr addObject:obj];
                            }
                        }
                    }
                }
            }
            if([dic count]>0){
                for (id key in dic) {
                    [array addObject:dic[key]];
                }
            }
            if([dic2 count]>0){
                for (id key in dic2) {
                    [array2 addObject:dic2[key]];
                }
            }
            if([array count]>0){
                NSIndexPath *indexPath=(NSIndexPath *)[self.DicIndexPath2 objectForKey:[NSNumber numberWithInteger:ID]];
                NSMutableArray *data =[NSMutableArray arrayWithObject:[[array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
                [HotPointDetail setData:[data firstObject]];
            }else{
                NSIndexPath *indexPath=(NSIndexPath *)[self.DicIndexPath objectForKey:[NSNumber numberWithInteger:self.indexID]];
                if([array2 count]>0){
                    NSMutableArray *data =[NSMutableArray arrayWithObject:[[array2 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
                    if([data count]>0){
                        [HotPointDetail setData:[data firstObject]];
                    }
                }
            }
            return;
        }
        if ([[root.viewControllers firstObject] isKindOfClass:SpaceIdeaView.class]) {
            SpaceIdeaView *Ideaclass = [root.viewControllers firstObject];
            [Ideaclass setData:[self.data objectForKey:@"idea"]];
            return;
        }
        return;
    }
    //
    if([segue.destinationViewController isKindOfClass:SpacePropertyContainer.class]){
        //软装套餐
        if([segue.identifier isEqualToString:@"SpacePropertyContainer1"]){
            ruanzhuang = [segue destinationViewController];
            ruanzhuang.onSelected1 = self.onSelected1;
            ruanzhuang.onSelected_rz = self.onSelected_rz;
            ruanzhuang.index = @"1";
            //
            ruanzhuang.onSelected_rz=^(id sender, id result){
                this.DicIndexPath2 = (NSMutableDictionary *)result;
            };
            ruanzhuang.onSelected1=^(id sender, id result){
                [this.tempArray removeAllObjects];
                SpacePropertyContainer *Container=(SpacePropertyContainer *)result;
                id dic;
                //
                NSIndexPath *indexpath=(NSIndexPath *)sender;
                [this.roomDic setValue:indexpath forKey:@"1"];
                if(Container.data&&[Container.data isKindOfClass:NSArray.class]){
                    dic =[Container.data objectAtIndex:indexpath.row];
                    this.value = dic;
                    [this displayLayer:dic index:nil layerid:1];
                }
                if(isEmpty(this.DicIndexPath2)&&!isEmpty([this feachForKey:@"2" object:this.roomDic])){
                    this.DicIndexPath2 =[this feachForKey:@"2" object:this.roomDic];
                    for(int i=0;i<[this.DicIndexPath2 count];i++){
                        ButtonLable *btn = (ButtonLable *)[this.layerView.tipsView viewWithTag:1000+i];
                        [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
                    }
                    return;
                }
                [this.DicIndexPath2 removeAllObjects];
                //选择风格后默认单品的选中状态。。。。。
                id item=[dic objectForKey:@"product_class"] ;
                for(int i=0;i<[item count];i++){
                    if([[[item objectAtIndex:i] objectForKey:@"class_product"] count]>0){
                        id items =[[[item objectAtIndex:i] objectForKey:@"class_product"] firstObject];
                        [this.tempArray setObject:[items objectForKey:@"id"] forKey:[NSNumber numberWithInt:i]];
                    }
                }
                //风格
                NSInteger lens = [[this.data objectForKey:@"house_sample_room_class"] count];
                for(int a=0;a<lens;a++){
                    id tp=[[this.data objectForKey:@"house_sample_room_class"] objectAtIndex:a] ;
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    //这里
                    this.newarray = [[NSMutableArray alloc]init];
                    if([[tp objectForKey:@"hardpacked"]integerValue]==1){
                        break;
                    }
                    id temp =[tp objectForKey:@"class_product"];
                    for (NSDictionary * obj in temp) {
                        NSString *parentid = [[obj objectForKey:@"product"] objectForKey:@"parentid"];
                        if(parentid){
                            if (dict[parentid] == nil) {
                                NSMutableArray *arr = [NSMutableArray array];
                                [arr addObject:obj];
                                dict[parentid] = arr;
                            }else{
                                NSMutableArray *arr = dict[parentid];
                                [arr addObject:obj];
                            }
                        }
                    }
                    for (id key in dict) {
                        [this.newarray addObject:dict[key]];
                    }
                    for(int s = 0;s<[this.tempArray count];s++){
                        for(int i=0;i<[this.newarray count];i++){
                            for(int j=0;j<[[this.newarray objectAtIndex:i] count];j++){
                                if([[this.tempArray objectForKey:[NSNumber numberWithInt:s]] intValue] == [[[[this.newarray objectAtIndex:i] objectAtIndex:j] objectForKey:@"id"] intValue]){
                                    NSIndexPath *indexpaths=[NSIndexPath indexPathForItem:j inSection:i];
                                    [this.DicIndexPath2 setObject:indexpaths forKey:[NSNumber numberWithInteger:a]];
                                }
                            }
                        }
                    }
                }
                [this.roomDic setObject:this.DicIndexPath2 forKey:@"2"];
            };
        }
        //软装单品
        if([segue.identifier isEqualToString:@"SpacePropertyContainer2"]){
            ruanzhuang_danpin = [segue destinationViewController];
            ruanzhuang_danpin.onSelected = self.onSelected;
            ruanzhuang_danpin.index = @"2";
            //
            ruanzhuang_danpin.onSelected=^(id sender, id result){
                NSIndexPath *indexpath=(NSIndexPath *)sender;
                SpacePropertyContainer *Container=(SpacePropertyContainer *)result;
                if([[[this.allroomDic objectForKey:@(this.roomID)] objectForKey:@"2"] count]>0){
                    this.DicIndexPath2 =[[this.allroomDic objectForKey:@(this.roomID)] objectForKey:@"2"];
                    
                }
                if([this feachForKey:[NSNumber numberWithInteger:this.pointID] object:this.DicIndexPath2]!=indexpath){
                    [this.DicIndexPath2 setObject:indexpath forKey:[NSNumber numberWithInteger:this.pointID]];
                }
                //
                [this.roomDic setValue:this.DicIndexPath2 forKey:@"2"];
                [this.allroomDic setObject:this.roomDic forKey:[NSNumber numberWithInteger:this.roomID]];
                //
                if(Container.data&&[Container.data isKindOfClass:NSArray.class]){
                    id dic =[[Container.data objectAtIndex:indexpath.row] objectForKey:@"angle_pic"];
                    if([dic count]>0){
                        this.value = dic;
                        [this displayLayer:dic index:Container layerid:2];
                    }
                }
            };
        }
        //硬装套餐
        if([segue.identifier isEqualToString:@"SpacePropertyContainer3"]){
            yingzhuang = [segue destinationViewController];
            yingzhuang.onSelected2 = self.onSelected2;
            yingzhuang.index = @"3";
            //
            yingzhuang.onSelected2=^(id sender, id result){
                SpacePropertyContainer *Container=(SpacePropertyContainer *)result;
                //
                NSIndexPath *indexpath=(NSIndexPath *)sender;
                [this.roomDic setValue:indexpath forKey:@"3"];
                //
                id dic = nil;
                if(Container.data&&[Container.data isKindOfClass:NSArray.class]){
                    dic = [Container.data objectAtIndex:indexpath.row];
                    this.value = dic;
                    [this displayLayer:dic index:nil layerid:3];
                }
                //
                if(isEmpty(this.DicIndexPath)&&!isEmpty([this feachForKey:@"4" object:this.roomDic])){
                    this.DicIndexPath =[this feachForKey:@"4" object:this.roomDic];
                    for(NSInteger i=[this.DicIndexPath2 count];i<[this.DicIndexPath count]+[this.DicIndexPath2 count];i++){
                        ButtonLable *btn = (ButtonLable *)[this.layerView.tipsView2 viewWithTag:1000+i];
                        btn.index = [NSString stringWithFormat:@"%ld",(long)(1000+i-[this.DicIndexPath2 count])];
                        [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
                    }
                    return;
                }
                //选择风格后默认单品的选中状态。。。。。
                id item=[dic objectForKey:@"product_class"] ;
                for(int i=0;i<[item count];i++){
                    if([[[item objectAtIndex:i] objectForKey:@"class_product"] count]>0){
                        id items =[[[item objectAtIndex:i] objectForKey:@"class_product"] firstObject];
                        [this.tempArray setObject:[items objectForKey:@"id"] forKey:[NSNumber numberWithInt:i]];
                    }
                }
                //
                NSMutableArray *muArray = [[NSMutableArray alloc]init];
                id it=[this.data objectForKey:@"house_sample_room_class"];
                for(int i=0;i<[it count];i++){
                    id itd = [it objectAtIndex:i];
                    if([[itd objectForKey:@"hardpacked"] intValue]==1){
                        [muArray addObject:itd];
                    }
                }
                //风格
                NSInteger lens=[muArray count];
                for(int a=0;a<lens;a++){
                    id tp=[muArray objectAtIndex:a] ;
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    this.newarray = [[NSMutableArray alloc]init];
                    id temp =[tp objectForKey:@"class_product"];
                    for (NSDictionary * obj in temp) {
                        NSString *parentid = [[obj objectForKey:@"product"] objectForKey:@"parentid"];
                        if(parentid){
                            if (dict[parentid] == nil) {
                                NSMutableArray *arr = [NSMutableArray array];
                                [arr addObject:obj];
                                dict[parentid] = arr;
                            }else{
                                NSMutableArray *arr = dict[parentid];
                                [arr addObject:obj];
                            }
                        }
                    }
                    for (id key in dict) {
                        [this.newarray addObject:dict[key]];
                    }
                    for(int s = 0;s<[this.tempArray count];s++){
                        for(int i=0;i<[this.newarray count];i++){
                            for(int j=0;j<[[this.newarray objectAtIndex:i] count];j++){
                                if([[this.tempArray objectForKey:[NSNumber numberWithInt:s]] intValue] == [[[[this.newarray objectAtIndex:i] objectAtIndex:j] objectForKey:@"id"] intValue]){
                                    NSIndexPath *indexpaths=[NSIndexPath indexPathForItem:j inSection:i];
                                    [this.DicIndexPath setObject:indexpaths forKey:[NSNumber numberWithInteger:a]];
                                }
                            }
                        }
                    }
                }
                [this.roomDic setObject:this.DicIndexPath forKey:@"4"];
            };
        }
        //硬装单品
        if([segue.identifier isEqualToString:@"SpacePropertyContainer4"]){
            yingzhuang_danpin = [segue destinationViewController];
            yingzhuang_danpin.onSelected3 = self.onSelected3;
            yingzhuang_danpin.onSelected_yz = self.onSelected_yz;
            yingzhuang_danpin.index = @"4";
            //
            yingzhuang_danpin.onSelected_yz=^(id sender, id result){
                this.DicIndexPath=(NSMutableDictionary *)result;
            };
            yingzhuang_danpin.onSelected3=^(id sender, id result){
                if(this.pointDic==nil){
                    this.pointDic = [NSMutableDictionary dictionary];
                    [this.typepointDic1 setObject:[NSNumber numberWithInteger:this.pointID_yz] forKey:[NSNumber numberWithInteger:this.indexID]];
                    [this.pointDic setValue:this.typepointDic1 forKey:@"4"];
                }
                //
                NSIndexPath *indexpath=(NSIndexPath *)sender;
                SpacePropertyContainer *Container=(SpacePropertyContainer *)result;
                if(indexpath){
                    this.DicIndexPath = [[this.allroomDic objectForKey:@(this.roomID)] objectForKey:@"4"];
                    if([this feachForKey:[NSNumber numberWithInteger:this.indexID] object:this.DicIndexPath]!=indexpath){
                        [this.DicIndexPath setObject:indexpath forKey:[NSNumber numberWithInteger:this.indexID]];
                    }
                    if(this.DicIndexPath){
                        [this.roomDic setValue:this.DicIndexPath forKey:@"4"];
                    }
                    //
                    id dic;
                    if(Container.data&&[Container.data isKindOfClass:NSArray.class]){
                        dic =[[Container.data objectAtIndex:indexpath.row] objectForKey:@"angle_pic"];
                        if([dic count]>0){
                            this.value = dic;
                            [this displayLayer:dic index:Container layerid:4];
                        }
                    }
                }
            };
        }
        [self.allroomDic setObject:self.roomDic forKey:[NSNumber numberWithInteger:self.roomID]];
        [self.pointroomDic setObject:self.pointDic forKey:@(self.roomID)];
    }
    bools++;
    if(bools==4){
        self.PropertyListView.hidden = YES;
        [self.bottomView setFrame:CGRectMake(0, self.view.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height)];
        return;
    }
    //
    if ([segue.destinationViewController isKindOfClass:UINavigationController.class]) {
        UINavigationController *ctrl = segue.destinationViewController;
        if ([[ctrl.viewControllers firstObject] isKindOfClass:UserCenterSelect.class]) {
            UserCenterSelect *root = [ctrl.viewControllers firstObject];
            [root setOnSelected:^(id target, id result){
                [this dismissViewControllerAnimated:YES completion:nil];
                if(result!=nil){
                    [TMGlobal setValue:result forKey:@"client"];
                    if ([segue.identifier isEqualToString:@"favoriteSegue"]) {
                        [self collectViewTouch:sender];
                    }
                }
            }];
        }
    }
}
-(id)feachForKey:(id)key object:(NSDictionary*)object{
    for (id k in object.allKeys) {
        if ([k intValue] == [key intValue]) {
            return [object objectForKey:k];
        }
    }
    return nil;
}
-(void)closeTouch{
    [UIView beginAnimations:nil context:nil];
    self.PropertyListView.hidden = YES;
    [self.topView setFrame:CGRectMake(0, self.view.frame.size.height, self.topView.frame.size.width, self.topView.frame.size.height)];
    self.bottomView.hidden = NO;
    [self.bottomView setFrame:CGRectMake(0, self.view.frame.size.height-self.bottomView.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height)];
    [UIView commitAnimations];
}


-(NSMutableArray *)getpointArray{
    NSMutableArray*LayerPointArray = [[NSMutableArray alloc]init];
    id point = [self.data objectForKey:@"house_sample_room_class_positions"];
    for(id  item in point){
        if(self.count==0){
            if([[item objectForKey:@"viewtype"] isEqualToString:@"viewpic1"]){
                [LayerPointArray addObject:item];
            }
        }else{
            if([[item objectForKey:@"viewtype"] isEqualToString:@"viewpic2"]){
                [LayerPointArray addObject:item];
            }
        }
        
    }
    return LayerPointArray;
}
-(void)creatPoint{
    //热点
    NSMutableArray*LayerPointArray = [[NSMutableArray alloc]init];
    LayerPointArray = [self getpointArray];
    NSInteger i=0;
    NSInteger j=0;
    
    for (id hotPoint in LayerPointArray) {
        
        float tp = self.view.frame.size.width/600.00;
        //软装      hardpacked : "0"
        if([[hotPoint objectForKey:@"hardpacked"] intValue]==0){
            CGPoint center=CGPointMake([[hotPoint objectForKey:@"posx"] floatValue]*tp, [[hotPoint objectForKey:@"posy"] floatValue]*tp);
            ButtonLable *tips=[[ButtonLable alloc]initWithFrame:CGRectMake(0,0, 23, 23)];
            [self.layerView.tipsView addSubview:tips];
            [tips setCenter:center];
            [tips setImage:[UIImage imageNamed:@"btn_House_Hot_nor.png"] forState:UIControlStateNormal];
            [tips setImage:[UIImage imageNamed:@"btn_House_Hot_sel.png"] forState:UIControlStateSelected];
            [tips addTarget:self action:@selector(tipsTouch:) forControlEvents:UIControlEventTouchUpInside];
            tips.tag=1000+i;
            tips.index =[hotPoint objectForKey:@"classid"];
            
            ButtonLable *tipsLable=[[ButtonLable alloc]initWithFrame:CGRectMake(0,0, 35, 35)];
            [self.layerView.lableView addSubview:tipsLable];
            [tipsLable setCenter:center];
            [tipsLable setImage:[UIImage imageNamed:@"btn_Estate_Label.png"] forState:UIControlStateNormal];
            [tipsLable addTarget:self action:@selector(tipsLableTouch:) forControlEvents:UIControlEventTouchUpInside];
            tipsLable.tag=[[hotPoint objectForKey:@"classid"] intValue];
            tipsLable.index = [NSString stringWithFormat:@"%ld",(long)(1000+i)];
            i++;
        }else{
            //硬装
            CGPoint center=CGPointMake([[hotPoint objectForKey:@"posx"] floatValue]*tp, [[hotPoint objectForKey:@"posy"] floatValue]*tp);
            ButtonLable *tips=[[ButtonLable alloc]initWithFrame:CGRectMake(0,0, 23, 23)];
            [self.layerView.tipsView2 addSubview:tips];
            [tips setCenter:center];
            [tips setImage:[UIImage imageNamed:@"btn_House_Hot_nor.png"] forState:UIControlStateNormal];
            [tips setImage:[UIImage imageNamed:@"btn_House_Hot_sel.png"] forState:UIControlStateSelected];
            [tips addTarget:self action:@selector(tipsTouch_yz:) forControlEvents:UIControlEventTouchUpInside];
            tips.tag=1000+i;
            tips.index=[NSString stringWithFormat:@"%ld",(long)(1000+j)];
            
            ButtonLable *tipsLable=[[ButtonLable alloc]initWithFrame:CGRectMake([[hotPoint objectForKey:@"posx"] floatValue]*tp, [[hotPoint objectForKey:@"posy"] floatValue]*tp, 35, 35)];
            [tipsLable setCenter:center];
            [self.layerView.lableView addSubview:tipsLable];
            [tipsLable setImage:[UIImage imageNamed:@"btn_Estate_Label.png"] forState:UIControlStateNormal];
            [tipsLable addTarget:self action:@selector(tipsLableTouch:) forControlEvents:UIControlEventTouchUpInside];
            tipsLable.tag=[[hotPoint objectForKey:@"classid"] intValue];
            tipsLable.index=[NSString stringWithFormat:@"%ld",(long)(1000 + j)];
            i++;
            j++;
            
        }
    }
    self.layerView.tipsView2.hidden = YES;
    self.layerView.tipsView.hidden = YES;
}
-(void)roomViewTouch:(UIButton *)sender{
    [UIView beginAnimations:nil context:nil];
    if(self.mapView.hidden){
        self.mapView.hidden = NO;
    }else{
        self.mapView.hidden = YES;
    }
    [UIView commitAnimations];
}
- (IBAction)backTouch:(id)sender {
    if(self.navigationController){
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
}
- (IBAction)buttonTouch:(UIButton *)sender {
    self.layerView.lableView.hidden = YES;
    self.container1.hidden = YES;
    self.container2.hidden = YES;
    self.container3.hidden = YES;
    self.container4.hidden = YES;
    //
    if(sender == self.buttonView1){
        self.btnindex=1;
        self.container1.hidden = NO;
        self.layerView.tipsView.hidden = YES;
        self.layerView.tipsView2.hidden = YES;
    }
    if(sender == self.buttonView2){
        self.container2.hidden = NO;
        self.layerView.tipsView.hidden = NO;
        self.layerView.tipsView2.hidden = YES;
        self.btnindex=2;
        [self updata_dp];
    }
    if(sender == self.buttonView3){
        self.btnindex=3;
        self.container3.hidden = NO;
        self.layerView.tipsView.hidden = YES;
        self.layerView.tipsView2.hidden = YES;
    }
    if(sender == self.buttonView4){
        self.btnindex=4;
        self.container4.hidden = NO;
        self.layerView.tipsView.hidden = YES;
        self.layerView.tipsView2.hidden = NO;
        [self updata_yzdp];
    }
    
    self.PropertyListView.hidden = NO;
    self._height.constant = 0;
    [self.view updateConstraintsIfNeeded];
    [UIView beginAnimations:nil context:nil];
    [self.view layoutIfNeeded];
    [UIView commitAnimations];
}


//
-(NSString*)dictionaryToSql:(NSDictionary*)dictionary from:(NSString*)from{
    NSArray *fields = [[TMSQLite shareInstance] query:[NSString stringWithFormat:@"PRAGMA table_info(%@)",from]];
    if (fields) {
        NSMutableArray *keys = [NSMutableArray array];
        NSMutableArray *vals = [NSMutableArray array];
        for (id tmp in fields) {
            id key = [tmp objectForKey:@"name"];
            id value = [dictionary valueForKey:key];
            if (value && [NSNull null] != value) {
                if ([NSJSONSerialization isValidJSONObject:value]){
                    value = [TMJSON stringify:value];
                }
                if ([value isKindOfClass:[NSString class]]) {
                    NSString *str = [value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
                    [vals addObject:[NSString stringWithFormat:@"'%@'",str]];
                }else{
                    [vals addObject:value];
                }
                [keys addObject:[NSString stringWithFormat:@"'%@'",key]];
            }
        }
        if (keys.count == vals.count && keys.count > 0) {
            id key = [keys componentsJoinedByString:@","];
            id value = [vals componentsJoinedByString:@","];
            return [NSString stringWithFormat:@"REPLACE INTO %@ (%@) VALUES (%@)", from, key, value];
        }
    }
    return nil;
}
//
- (id)getAllSuit:(id)suitid{
    if ([[UIDevice currentDevice] network] != UIDeviceNetworkNone) {
        id user = [TMGlobal valueForKey:@"user"];
        if (user) {
            NSString *tmp = [NSString stringWithFormat:@"%@?n=api&a=suit&c=suit&id=%@&token=%@",AppDataRoot,suitid,[user objectForKey:@"utoken"]];
            NSURL *url = [NSURL URLWithString:tmp];
            TMLoader *loader = [TMLoader load:[TMRequest requestWithURL:url data:nil] delegate:nil cache:1];
            if (loader) {
                NSString *json = [[NSString alloc ] initWithData:loader.data encoding:NSUTF8StringEncoding];
                id dat = [TMJSON parse:json];
                if([dat count] == 0){
                    return nil;
                }
                //套餐
                [[[TMSQLite shareInstance] transaction] begin];
                NSArray *room_match = [dat objectForKey:@"house_sample_room_match"];
                for(id roommatch in room_match){
                    NSArray *productclass = [roommatch objectForKey:@"product_class"];
                    for(id pc in productclass){
                        NSArray *classproduct = [pc objectForKey:@"class_product"];
                        for(id cp in classproduct){
                            NSMutableDictionary *product =[cp objectForKey:@"product"];
                            if(product){
                                id productsub = [product objectForKey:@"product_sub"];
                                if([productsub count]>0){
                                    for(id pt in productsub){
                                        NSString *sql = [self dictionaryToSql:pt from:@"e360_product_sub"];
                                        [[TMSQLite shareInstance] query:sql];
                                    }
                                }
                                NSArray *sub = [product objectForKey:@"sub"];
                                if([sub count] > 0){
                                    for(id product in sub){
                                        NSString *sql = [self dictionaryToSql:product from:@"e360_product"];
                                        [[TMSQLite shareInstance] query:sql];
                                    }
                                }
                                NSString *sql = [self dictionaryToSql:product from:@"e360_product"];
                                [[TMSQLite shareInstance] query:sql];
                            }
                            //
                            NSArray *anglepic = [cp objectForKey:@"angle_pic"];
                            for(id pic in anglepic){
                                NSString *sql = [self dictionaryToSql:pic from:@"e360_house_sample_room_class_product_angle_pic"];
                                [[TMSQLite shareInstance] query:sql];
                            }
                            id relation = [cp objectForKey:@"house_sample_room_match_relation"];
                            if(relation){
                                NSString *sqls = [self dictionaryToSql:relation from:@"e360_house_sample_room_match_relation"];
                                [[TMSQLite shareInstance] query:sqls];
                            }
                            //
                            NSMutableDictionary *temp = [NSMutableDictionary dictionaryWithDictionary:cp];
                            [temp setValue:nil forKey:@"product"];
                            [temp setValue:nil forKey:@"angle_pic"];
                            [temp setValue:nil forKey:@"house_sample_room_match_relation"];
                            NSString *sql = [self dictionaryToSql:temp from:@"e360_house_sample_room_class_product"];
                            [[TMSQLite shareInstance] query:sql];
                        }
                        NSString *sql = [self dictionaryToSql:pc from:@"e360_house_sample_room_class"];
                        [[TMSQLite shareInstance] query:sql];
                    }
                    id classs =[roommatch objectForKey:@"house_sample_room_match_class"];
                    if([classs count]>0){
                        NSString *sql = [self dictionaryToSql:classs from:@"e360_house_sample_room_match_class"];
                        [[TMSQLite shareInstance] query:sql];
                    }
                    NSString *sql = [self dictionaryToSql:roommatch from:@"e360_house_sample_room_match"];
                    [[TMSQLite shareInstance] query:sql];
                }
                //单品
                NSArray *room_class = [dat objectForKey:@"house_sample_room_class"];
                for(id roomclass in room_class){
                    NSArray *classproduct = [roomclass objectForKey:@"class_product"];
                    for(id cp in classproduct){
                        NSMutableDictionary *product =[cp objectForKey:@"product"];
                        if(product){
                            id productsub = [product objectForKey:@"product_sub"];
                            if([productsub count]>0){
                                for(id pt in productsub){
                                    NSString *sql = [self dictionaryToSql:pt from:@"e360_product_sub"];
                                    [[TMSQLite shareInstance] query:sql];
                                }
                            }
                            //
                            NSArray *sub = [product objectForKey:@"sub"];
                            if([sub count] > 0){
                                for(id product in sub){
                                    id modelinfo = [product objectForKey:@"model_info"];
                                    if(modelinfo){
                                        id products = [modelinfo objectForKey:@"product"];
                                        if([products isKindOfClass:NSDictionary.class]){
                                            NSString *sql = [self dictionaryToSql:products from:@"e360_product_model_material_match_subproduct"];
                                            [[TMSQLite shareInstance] query:sql];
                                        }
                                        //
                                        id model = [modelinfo objectForKey:@"model"];
                                        if(model){
                                            NSString *sql = [self dictionaryToSql:model from:@"e360_product_model"];
                                            [[TMSQLite shareInstance] query:sql];
                                            //
                                            if([model isKindOfClass:NSDictionary.class]){
                                                id materialclass =[model objectForKey:@"material_class"];
                                                if([materialclass count]>0){
                                                    for(id tp in materialclass){
                                                        NSString *sql = [self dictionaryToSql:tp from:@"e360_product_model_material_class"];
                                                        [[TMSQLite shareInstance] query:sql];
                                                    }
                                                }
                                                //
                                                id material =[model objectForKey:@"material"];
                                                if([material count]>0){
                                                    for(id tp in material){
                                                        NSString *sql = [self dictionaryToSql:tp from:@"e360_product_material"];
                                                        [[TMSQLite shareInstance] query:sql];
                                                        //
                                                        id color =[tp objectForKey:@"color"];
                                                        if(color){
                                                            if([color isKindOfClass:NSDictionary.class]){
                                                                NSString *sql = [self dictionaryToSql:color from:@"e360_product_color"];
                                                                [[TMSQLite shareInstance] query:sql];
                                                            }
                                                        }
                                                        //
                                                        id productmodelmaterial =[tp objectForKey:@"product_model_material"];
                                                        if(productmodelmaterial){
                                                            if([productmodelmaterial isKindOfClass:NSDictionary.class]){
                                                                NSString *sql = [self dictionaryToSql:productmodelmaterial from:@"e360_product_model_material"];
                                                                [[TMSQLite shareInstance] query:sql];
                                                            }
                                                        }
                                                    }
                                                }
                                                id match =[model objectForKey:@"match"];
                                                if([match isKindOfClass:NSDictionary.class]){
                                                    NSString *sql = [self dictionaryToSql:match from:@"e360_product_model_material_match"];
                                                    [[TMSQLite shareInstance] query:sql];
                                                }
                                            }
                                        }
                                    }
                                    NSString *sql = [self dictionaryToSql:product from:@"e360_product"];
                                    [[TMSQLite shareInstance] query:sql];
                                }
                            }
                            NSString *sql = [self dictionaryToSql:product from:@"e360_product"];
                            [[TMSQLite shareInstance] query:sql];
                        }
                        NSArray *anglepic = [cp objectForKey:@"angle_pic"];
                        for(id pic in anglepic){
                            NSString *sql = [self dictionaryToSql:pic from:@"e360_house_sample_room_class_product_angle_pic"];
                            [[TMSQLite shareInstance] query:sql];
                        }
                        id relation = [dat objectForKey:@"house_sample_room_match_relation"];
                        if(relation){
                            NSString *sqls = [self dictionaryToSql:relation from:@"e360_house_sample_room_match_relation"];
                            [[TMSQLite shareInstance] query:sqls];
                        }
                        NSString *sql = [self dictionaryToSql:cp from:@"e360_house_sample_room_class_product"];
                        [[TMSQLite shareInstance] query:sql];
                    }
                    NSString *sql = [self dictionaryToSql:roomclass from:@"e360_house_sample_room_class"];
                    [[TMSQLite shareInstance] query:sql];
                }
                //热点
                NSArray *class_positions = [dat objectForKey:@"house_sample_room_class_positions"];
                if([class_positions count] > 0){
                    for(id position in class_positions){
                        NSString *sql = [self dictionaryToSql:position from:@"e360_mjt_suit_product_pos"];
                        [[TMSQLite shareInstance] query:sql];
                    }
                }
                //detail
                NSArray *detail = [dat objectForKey:@"detail"];
                if([detail count] > 0){
                    for(id det in detail){
                        NSMutableDictionary *class = [det objectForKey:@"class"];
                        if(class){
                            NSString *sql = [self dictionaryToSql:class from:@"e360_scheme_match_class"];
                            [[TMSQLite shareInstance] query:sql];
                        }
                        NSMutableDictionary *parent = [det objectForKey:@"parent"];
                        if(parent){
                            NSString *sql = [self dictionaryToSql:parent from:@"e360_scheme_match_class"];
                            [[TMSQLite shareInstance] query:sql];
                        }
                        NSString *sql = [self dictionaryToSql:det from:@"e360_mjt_suit_detail"];
                        [[TMSQLite shareInstance] query:sql];
                    }
                }
                NSString *sql = [self dictionaryToSql:dat from:@"e360_mjt_suit"];
                [[TMSQLite shareInstance] query:sql];
            }
            [[[TMSQLite shareInstance] transaction] commit];
        }
    }
    //
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    NSString *sql = [NSString stringWithFormat:@"SELECT *FROM e360_mjt_suit WHERE id=%@  and deleted=0 ", suitid];
    id items = [[TMSQLite shareInstance] query:sql];
    dic = [items firstObject];
    //套餐
    NSString *sqls = [NSString stringWithFormat:@"SELECT *FROM e360_house_sample_room_match WHERE suitid=%@  and deleted=0  ", suitid];
    id tp = [[TMSQLite shareInstance] query:sqls];
    for(id tmp in tp){
        //
        NSString *sqls = [NSString stringWithFormat:@"SELECT *FROM e360_house_sample_room_match_class WHERE id=%@  and deleted=0  ", [tmp objectForKey:@"matchclassid"]];
        id dat = [[TMSQLite shareInstance] query:sqls];
        if(dat){
            [tmp setValue:[dat firstObject] forKey:@"house_sample_room_match_class"];
        }
        //
        NSString *sql = [NSString stringWithFormat:@"SELECT b.*FROM e360_house_sample_room_match_relation a,e360_house_sample_room_class b WHERE a.classid=b.id and a.matchid=%@  and a.deleted=0  and b.deleted=0 ", [tmp objectForKey:@"id"]];
        id dats = [[TMSQLite shareInstance] query:sql];
        if(dats){
            for(id pro in dats){
                NSString *sql = [NSString stringWithFormat:@"SELECT b.* FROM e360_house_sample_room_match_relation a,e360_house_sample_room_class_product b WHERE a.classproductid=b.id AND a.matchid=%@ AND a.classid=%@  and a.deleted=0  and b.deleted=0 ",[tmp objectForKey:@"id"], [pro objectForKey:@"id"]];
                id dats = [[TMSQLite shareInstance] query:sql];
                if(dats)
                {
                    for(id tp in dats){
                        //
                        NSString *sql = [NSString stringWithFormat:@"SELECT a.*,b.productcount FROM e360_product a,e360_house_sample_room_class_product b WHERE a.id = b.productid and a.id = %@  and a.deleted=0  and b.deleted=0 GROUP BY a.id ",[tp objectForKey:@"productid"]];
                        id _dat = [[TMSQLite shareInstance] query:sql];
                        if(_dat){
                            //
                            NSMutableArray *subs = [[NSMutableArray alloc]init];
                            id tps =[_dat firstObject];
                            if([[tps objectForKey:@"hassub"] integerValue]==1)
                            {
                                NSString *sqlt = [NSString stringWithFormat:@"SELECT *FROM e360_product_sub b WHERE b.productid = %@  and b.deleted=0 ",[tps objectForKey:@"id"]];
                                id datt = [[TMSQLite shareInstance] query:sqlt];
                                if(datt){
                                    for(id sub in datt)
                                    {
                                
                                        NSString *sqlt = [NSString stringWithFormat:@"SELECT a.*,b.productcount FROM e360_product a,e360_product_sub b WHERE a.id=b.subid AND a.id=%@ and a.deleted=0 and b.deleted=0 ",[sub objectForKey:@"subid"]];
                                        id datsub = [[TMSQLite shareInstance] query:sqlt];
                                        if(datsub){
                                            
                                            id  dat =[datsub firstObject];
                                            //
                                            NSMutableDictionary *ds = [NSMutableDictionary dictionary];
                                            if (isEmpty([dat objectForKey:@"subproductid"])==NO) {
                                                
                                                sql = [NSString stringWithFormat:@"SELECT * FROM e360_product_model_material_match_subproduct WHERE id=%@ and deleted=0 ",[dat objectForKey:@"subproductid"]];
                                                NSMutableDictionary *info = [[[TMSQLite shareInstance] query:sql] firstObject];
                                                [ds setValue:info forKey:@"product"];
                                                if (info) {
                                                    sql = [NSString stringWithFormat:@"SELECT b.* FROM e360_product_model_material_match a,e360_product_model b WHERE a.model_id=b.id AND a.id=%@ and a.deleted=0 and b.deleted=0 ",[info objectForKey:@"match_id"]];
                                                    NSMutableDictionary *model = [[[TMSQLite shareInstance] query:sql] firstObject];
                                                    if (model) {
                                                        sql = [NSString stringWithFormat:@"SELECT a.* FROM e360_product_material a, e360_product_model_material b, e360_product_model_material_class c ,e360_product_model_material_match d WHERE d.id=b.match_id AND c.id=b.class_id AND b.material_id=a.id AND c.model_id=%@ and d.id=%@ and a.deleted=0 and b.deleted=0 and c.deleted=0 and d.deleted=0 ",[model objectForKey:@"id"],[info objectForKey:@"id"]];
                                                        NSArray *materials = [[TMSQLite shareInstance] query:sql];
                                                        if (materials) {
                                                            [model setValue:materials forKey:@"material"];
                                                            //
                                                            for (id material in materials) {
                                                                sql = [NSString stringWithFormat:@"SELECT * FROM e360_product_color WHERE id=%@ and deleted=0 ",[material objectForKey:@"colorid"]];
                                                                NSDictionary *color = [[[TMSQLite shareInstance] query:sql] firstObject];
                                                                if (color) {
                                                                    [material setValue:color forKey:@"color"];
                                                                    [material setValue:[color objectForKey:@"colorname"] forKey:@"colorname"];
                                                                }
                                                            }
                                                        }
                                                        
                                                        [ds setValue:model forKey:@"model"];
                                                    }
                                                    [dat setValue:ds forKey:@"model_info"];
                                                }
                                            }
                                            [subs addObject:dat];
                                        }
                                    }
                                    if([subs count]>0){
                                        [tps setValue:subs forKey:@"sub"];
                                    }
                                }
                            }
                            [tp setValue:[_dat firstObject] forKey:@"product"];
                        }
                        //
                        NSString *sqls = [NSString stringWithFormat:@"SELECT *FROM e360_house_sample_room_class_product_angle_pic WHERE class_product_id=%@ and deleted=0 GROUP BY angle ",[tp objectForKey:@"id"]];
                        id _dats = [[TMSQLite shareInstance] query:sqls];
                        if(_dats){
                            [tp setValue:_dats forKey:@"angle_pic"];
                        }
                    }
                    [pro setValue:dats forKey:@"class_product"];
                }
            }
            [tmp setValue:dats forKey:@"product_class"];
        }
    }
    if(tp){
        [dic setValue:tp forKey:@"house_sample_room_match"];
    }
    //单品
    NSString *_sql = [NSString stringWithFormat:@"SELECT * FROM e360_house_sample_room_class WHERE suitid=%@ and deleted=0 ", suitid];
    id _tp = [[TMSQLite shareInstance] query:_sql];
    if(_tp){
        for(id item in _tp)
        {
            NSString *sql = [NSString stringWithFormat:@"SELECT *FROM e360_house_sample_room_class_product WHERE classid = %@ and deleted=0 ",[item objectForKey:@"id"]];
            id dats = [[TMSQLite shareInstance] query:sql];
            if(dats)
            {
                for(id it in dats)
                {
                    NSString *sql = [NSString stringWithFormat:@"SELECT a.*,b.productcount FROM e360_product a,e360_house_sample_room_class_product b WHERE a.id = b.productid and a.id = %@ and a.deleted=0 and b.deleted=0 GROUP BY a.id",[it objectForKey:@"productid"]];
                    id _dat = [[TMSQLite shareInstance] query:sql];
                    if(_dat == nil){
                        NSString *sql = [NSString stringWithFormat:@"SELECT a.*,productid id,1 hassub FROM e360_product_sub a WHERE a.productid = %@ and a.deleted=0 ",[it objectForKey:@"productid"]];
                        _dat = [[TMSQLite shareInstance] query:sql];
                    }
                    if(_dat){
                        //
                        NSMutableArray *subs = [[NSMutableArray alloc]init];
                        id tps =[_dat firstObject];
                        if([[tps objectForKey:@"hassub"] integerValue]==1)
                        {
                            NSString *sqlt = [NSString stringWithFormat:@"SELECT *FROM e360_product_sub b WHERE b.productid = %@ and b.deleted=0 ",[tps objectForKey:@"id"]];
                            id datt = [[TMSQLite shareInstance] query:sqlt];
                            if(datt)
                            {
                                for(id sub in datt)
                                {
                                    NSString *sqlt = [NSString stringWithFormat:@"SELECT a.*,b.productcount FROM e360_product a,e360_product_sub b WHERE a.id=b.subid AND a.id=%@ and a.deleted=0 and b.deleted=0 ",[sub objectForKey:@"subid"]];
                                    id datsub = [[TMSQLite shareInstance] query:sqlt];
                                    if(datsub)
                                    {
                                        id dat =[datsub firstObject];
                                        //
                                        
                                        NSMutableDictionary *ds = [NSMutableDictionary dictionary];
                                        if (isEmpty([dat objectForKey:@"subproductid"])==NO) {
                                            
                                            sql = [NSString stringWithFormat:@"SELECT * FROM e360_product_model_material_match_subproduct WHERE id=%@ and deleted=0 ",[dat objectForKey:@"subproductid"]];
                                            NSMutableDictionary *info = [[[TMSQLite shareInstance] query:sql] firstObject];
                                            [ds setValue:info forKey:@"product"];
                                            if (info) {
                                                sql = [NSString stringWithFormat:@"SELECT b.* FROM e360_product_model_material_match a,e360_product_model b WHERE a.model_id=b.id AND a.id=%@ and a.deleted=0 and b.deleted=0 ",[info objectForKey:@"match_id"]];
                                                NSMutableDictionary *model = [[[TMSQLite shareInstance] query:sql] firstObject];
                                                if (model) {
                                                    sql = [NSString stringWithFormat:@"SELECT a.* FROM e360_product_material a, e360_product_model_material b, e360_product_model_material_class c ,e360_product_model_material_match d WHERE d.id=b.match_id AND c.id=b.class_id AND b.material_id=a.id AND c.model_id=%@ and d.id=%@ and a.deleted=0 and b.deleted=0 and c.deleted=0 and d.deleted=0 ",[model objectForKey:@"id"],[info objectForKey:@"match_id"]];
                                                    NSArray *materials = [[TMSQLite shareInstance] query:sql];
                                                    if (materials) {
                                                        [model setValue:materials forKey:@"material"];
                                                        //
                                                        for (id material in materials) {
                                                            sql = [NSString stringWithFormat:@"SELECT * FROM e360_product_color WHERE id=%@ and deleted=0 ",[material objectForKey:@"colorid"]];
                                                            NSDictionary *color = [[[TMSQLite shareInstance] query:sql] firstObject];
                                                            if (color) {
                                                                [material setValue:color forKey:@"color"];
                                                                [material setValue:[color objectForKey:@"colorname"] forKey:@"colorname"];
                                                            }
                                                        }
                                                    }
                                                    
                                                    [ds setValue:model forKey:@"model"];
                                                }
                                                [dat setValue:ds forKey:@"model_info"];
                                            }
                                        }
                                        
                                        [subs addObject:dat];
                                    }
                                }
                                if([subs count]>0){
                                    [tps setValue:subs forKey:@"sub"];
                                }
                            }

                            
                        }
                        //
                        [it setValue:[_dat firstObject] forKey:@"product"];
                    }
                    //
                    NSString *sqls = [NSString stringWithFormat:@"SELECT *FROM e360_house_sample_room_class_product_angle_pic WHERE class_product_id=%@ and deleted=0 GROUP BY angle",[it objectForKey:@"id"]];
                    id _dats = [[TMSQLite shareInstance] query:sqls];
                    if(_dats){
                        [it setValue:_dats forKey:@"angle_pic"];
                    }
                    //
                }
                [item setValue:dats forKey:@"class_product"];
            }
        }
        [dic setValue:_tp forKey:@"house_sample_room_class"];
    }
    //热点
    NSString *hotsql = [NSString stringWithFormat:@"SELECT a.*,b.hardpacked FROM e360_mjt_suit_product_pos a,e360_house_sample_room_class b WHERE a.classid=b.id AND a.suitid=%@  and a.deleted=0 and b.deleted=0 ", suitid];
    id hottp = [[TMSQLite shareInstance] query:hotsql];
    if(hottp){
        [dic setValue:hottp forKey:@"house_sample_room_class_positions"];
    }
    //
    NSString *detailsql = [NSString stringWithFormat:@"SELECT *FROM e360_mjt_suit_detail WHERE suitid=%@ and deleted=0", suitid];
    id detailtp = [[TMSQLite shareInstance] query:detailsql];
    if(detailtp){
        for(id detail in detailtp){
            NSString *detail_sql = [NSString stringWithFormat:@"SELECT *FROM e360_scheme_match_class WHERE id=%@  and deleted=0 ", [detail objectForKey:@"classid"]];
            id detail_tp = [[TMSQLite shareInstance] query:detail_sql];
            if(detail_tp){
                [detail setValue:[detail_tp firstObject] forKey:@"class"];
                
                NSString *detail_sqls = [NSString stringWithFormat:@"SELECT *FROM e360_scheme_match_class WHERE id=%@ and deleted=0 ", [[detail_tp firstObject] objectForKey:@"parentid"]];
                id detail_tps = [[TMSQLite shareInstance] query:detail_sqls];
                if(detail_tps){
                    [detail setValue:[detail_tps firstObject] forKey:@"parent"];
                }
            }
            //
        }
        [dic setValue:detailtp forKey:@"detail"];
    }
    return dic;
}
@end
